Skip to content
Snippets Groups Projects
Commit 1a1ceace authored by ballen4705's avatar ballen4705
Browse files

Experimental generalization of code to run arbitrary scripts.

git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@465 4ea69e1a-61f1-4043-bf83-b5c94c648137
parent a07c1a2f
No related branches found
No related tags found
No related merge requests found
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
// CVS ID strings // CVS ID strings
extern const char *atacmds_c_cvsid, *ataprint_c_cvsid, *scsicmds_c_cvsid, *utility_c_cvsid; extern const char *atacmds_c_cvsid, *ataprint_c_cvsid, *scsicmds_c_cvsid, *utility_c_cvsid;
const char *smartd_c_cvsid="$Id: smartd.c,v 1.100 2003/01/27 22:49:05 ballen4705 Exp $" const char *smartd_c_cvsid="$Id: smartd.c,v 1.101 2003/01/29 16:11:24 ballen4705 Exp $"
ATACMDS_H_CVSID ATAPRINT_H_CVSID EXTERN_H_CVSID SCSICMDS_H_CVSID SMARTD_H_CVSID UTILITY_H_CVSID; ATACMDS_H_CVSID ATAPRINT_H_CVSID EXTERN_H_CVSID SCSICMDS_H_CVSID SMARTD_H_CVSID UTILITY_H_CVSID;
// global variable used for control of printing, passing arguments, etc. // global variable used for control of printing, passing arguments, etc.
...@@ -118,7 +118,7 @@ void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){ ...@@ -118,7 +118,7 @@ void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){
va_list ap; va_list ap;
const int day=24*3600; const int day=24*3600;
int days=0; int days=0;
char *address=cfg->address; char *address=cfg->address,*mailer;
mailinfo *mail=cfg->maildata+which; mailinfo *mail=cfg->maildata+which;
// See if user wants us to send mail // See if user wants us to send mail
...@@ -191,8 +191,25 @@ void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){ ...@@ -191,8 +191,25 @@ void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){
sprintf(original,"The original email about this issue was sent at %s\n",ctime(&(mail->firstsent))); sprintf(original,"The original email about this issue was sent at %s\n",ctime(&(mail->firstsent)));
} }
// If the user has set environment variable SMARTD_MAILER, use that
// as the mail program. Otherwise use /bin/mail.
if (!(mailer=getenv("SMARTD_MAILER"))){
printout(LOG_INFO,"Environment variable SMARTD_MAILER not set; using /bin/mail\n");
putenv("SMARTD_MAILER=/bin/mail");
}
else
printout(LOG_INFO,"Using environment variable SMARTD_MAILER=%s\n",mailer);
// Export information in environment variables that will be useful
// for user scripts
setenv("SMARTD_DEVICE", cfg->name, 1);
setenv("SMARTD_MESSAGE", message, 1);
setenv("SMARTD_ADDRESS", address, 1);
setenv("SMARTD_TFIRST", ctime(&(mail->firstsent)), 1);
// now construct a command to send this as EMAIL // now construct a command to send this as EMAIL
snprintf(command, 2048, "mail -s 'SMART errors detected on host: %s' %s > /dev/null 2> /dev/null << \"ENDMAIL\"\n" snprintf(command, 2048,
"$SMARTD_MAILER -s 'SMART errors detected on host: %s' %s > /dev/null 2> /dev/null << \"ENDMAIL\"\n"
"This email was generated by the smartd daemon running on host:\n" "This email was generated by the smartd daemon running on host:\n"
"%s in domain: %s\n\n" "%s in domain: %s\n\n"
"The following warning/error was logged by the smartd daemon:\n" "The following warning/error was logged by the smartd daemon:\n"
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
// CVS ID strings // CVS ID strings
extern const char *atacmds_c_cvsid, *ataprint_c_cvsid, *scsicmds_c_cvsid, *utility_c_cvsid; extern const char *atacmds_c_cvsid, *ataprint_c_cvsid, *scsicmds_c_cvsid, *utility_c_cvsid;
const char *smartd_c_cvsid="$Id: smartd.cpp,v 1.100 2003/01/27 22:49:05 ballen4705 Exp $" const char *smartd_c_cvsid="$Id: smartd.cpp,v 1.101 2003/01/29 16:11:24 ballen4705 Exp $"
ATACMDS_H_CVSID ATAPRINT_H_CVSID EXTERN_H_CVSID SCSICMDS_H_CVSID SMARTD_H_CVSID UTILITY_H_CVSID; ATACMDS_H_CVSID ATAPRINT_H_CVSID EXTERN_H_CVSID SCSICMDS_H_CVSID SMARTD_H_CVSID UTILITY_H_CVSID;
// global variable used for control of printing, passing arguments, etc. // global variable used for control of printing, passing arguments, etc.
...@@ -118,7 +118,7 @@ void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){ ...@@ -118,7 +118,7 @@ void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){
va_list ap; va_list ap;
const int day=24*3600; const int day=24*3600;
int days=0; int days=0;
char *address=cfg->address; char *address=cfg->address,*mailer;
mailinfo *mail=cfg->maildata+which; mailinfo *mail=cfg->maildata+which;
// See if user wants us to send mail // See if user wants us to send mail
...@@ -191,8 +191,25 @@ void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){ ...@@ -191,8 +191,25 @@ void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){
sprintf(original,"The original email about this issue was sent at %s\n",ctime(&(mail->firstsent))); sprintf(original,"The original email about this issue was sent at %s\n",ctime(&(mail->firstsent)));
} }
// If the user has set environment variable SMARTD_MAILER, use that
// as the mail program. Otherwise use /bin/mail.
if (!(mailer=getenv("SMARTD_MAILER"))){
printout(LOG_INFO,"Environment variable SMARTD_MAILER not set; using /bin/mail\n");
putenv("SMARTD_MAILER=/bin/mail");
}
else
printout(LOG_INFO,"Using environment variable SMARTD_MAILER=%s\n",mailer);
// Export information in environment variables that will be useful
// for user scripts
setenv("SMARTD_DEVICE", cfg->name, 1);
setenv("SMARTD_MESSAGE", message, 1);
setenv("SMARTD_ADDRESS", address, 1);
setenv("SMARTD_TFIRST", ctime(&(mail->firstsent)), 1);
// now construct a command to send this as EMAIL // now construct a command to send this as EMAIL
snprintf(command, 2048, "mail -s 'SMART errors detected on host: %s' %s > /dev/null 2> /dev/null << \"ENDMAIL\"\n" snprintf(command, 2048,
"$SMARTD_MAILER -s 'SMART errors detected on host: %s' %s > /dev/null 2> /dev/null << \"ENDMAIL\"\n"
"This email was generated by the smartd daemon running on host:\n" "This email was generated by the smartd daemon running on host:\n"
"%s in domain: %s\n\n" "%s in domain: %s\n\n"
"The following warning/error was logged by the smartd daemon:\n" "The following warning/error was logged by the smartd daemon:\n"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment