diff --git a/sm5/smartd.c b/sm5/smartd.c index 410c2f677f06832547b9f60647023cb41017e893..25b5f24a37525acf55d17c0a385ec7e1a336dd10 100644 --- a/sm5/smartd.c +++ b/sm5/smartd.c @@ -45,7 +45,7 @@ // CVS ID strings extern const char *CVSid1, *CVSid2; -const char *CVSid6="$Id: smartd.c,v 1.56 2002/11/12 21:16:25 ballen4705 Exp $" +const char *CVSid6="$Id: smartd.c,v 1.57 2002/11/12 21:53:52 ballen4705 Exp $" CVSID1 CVSID2 CVSID3 CVSID4 CVSID7; // global variable used for control of printing, passing arguments, etc. @@ -92,13 +92,7 @@ void printout(int priority,char *fmt, ...){ void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){ int pid; va_list ap; - - // iitialize variable argument list, then log message to SYSLOG or - // stdout, then finish with argument list - va_start(ap,fmt); - printout(priority, fmt, ap); - va_end(ap); - + // See if user wants us to send mail if (!address) return; @@ -142,6 +136,8 @@ void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){ // now construct a command to send this as EMAIL, and issue it. snprintf(command,1024, "echo '%s' | mail -s '%s: smartd detected SMART errors' %s > /dev/null 2> /dev/null", message, hostname, address); + + // we should uninstall exit handler! exit(system(command)); } } @@ -600,8 +596,10 @@ int ataCheckDevice(atadevices_t *drive){ int status=ataSmartStatus2(fd); if (status==-1) printout(LOG_INFO,"Device: %s, not capable of SMART self-check\n",name); - else if (status==1) + else if (status==1){ + printout(LOG_CRIT, "Device: %s, FAILED SMART self-check. BACK UP DATA NOW!\n", name); printandmail(cfg->address, cfg->maildata , LOG_CRIT, "Device: %s, FAILED SMART self-check. BACK UP DATA NOW!\n", name); + } } // Check everything that depends upon SMART Data (eg, Attribute values) @@ -632,6 +630,7 @@ int ataCheckDevice(atadevices_t *drive){ while (*loc && *loc==' ') loc++; // warning message + printout(LOG_CRIT, "Device: %s, Failed SMART usage Attribute: %s.\n", name, loc); printandmail(cfg->address, cfg->maildata+1, LOG_CRIT, "Device: %s, Failed SMART usage Attribute: %s.\n", name, loc); } } @@ -680,8 +679,10 @@ int ataCheckDevice(atadevices_t *drive){ unsigned char old=cfg->selflogcount; int new=selftesterrorcount(fd, name); if (new>old){ - printandmail(cfg->address, cfg->maildata+2, LOG_CRIT, "Device: %s, Self-Test Log error count increased from %d to %d\n", + printout(LOG_CRIT, "Device: %s, Self-Test Log error count increased from %d to %d\n", name, (int)old, new); + printandmail(cfg->address, cfg->maildata+2, LOG_CRIT, "Device: %s, Self-Test Log error count increased from %d to %d\n", + name, (int)old, new); } if (new>=0) // Needed suince self-test error count may DECREASE @@ -694,8 +695,10 @@ int ataCheckDevice(atadevices_t *drive){ int old=cfg->ataerrorcount; int new=ataerrorcount(fd, name); if (new>old){ - printandmail(cfg->address, cfg->maildata+3, LOG_CRIT, "Device: %s, ATA error count increased from %d to %d\n", + printout(LOG_CRIT, "Device: %s, ATA error count increased from %d to %d\n", name, old, new); + printandmail(cfg->address, cfg->maildata+3, LOG_CRIT, "Device: %s, ATA error count increased from %d to %d\n", + name, old, new); } // this last line is probably not needed, count always increases if (new>=0) diff --git a/sm5/smartd.cpp b/sm5/smartd.cpp index 2b67f290de3c7132c411c1b6fbbb8477d7067c99..bf8675ba8d4b19034a0b0343b4b3e17f2c2a1612 100644 --- a/sm5/smartd.cpp +++ b/sm5/smartd.cpp @@ -45,7 +45,7 @@ // CVS ID strings extern const char *CVSid1, *CVSid2; -const char *CVSid6="$Id: smartd.cpp,v 1.56 2002/11/12 21:16:25 ballen4705 Exp $" +const char *CVSid6="$Id: smartd.cpp,v 1.57 2002/11/12 21:53:52 ballen4705 Exp $" CVSID1 CVSID2 CVSID3 CVSID4 CVSID7; // global variable used for control of printing, passing arguments, etc. @@ -92,13 +92,7 @@ void printout(int priority,char *fmt, ...){ void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){ int pid; va_list ap; - - // iitialize variable argument list, then log message to SYSLOG or - // stdout, then finish with argument list - va_start(ap,fmt); - printout(priority, fmt, ap); - va_end(ap); - + // See if user wants us to send mail if (!address) return; @@ -142,6 +136,8 @@ void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){ // now construct a command to send this as EMAIL, and issue it. snprintf(command,1024, "echo '%s' | mail -s '%s: smartd detected SMART errors' %s > /dev/null 2> /dev/null", message, hostname, address); + + // we should uninstall exit handler! exit(system(command)); } } @@ -600,8 +596,10 @@ int ataCheckDevice(atadevices_t *drive){ int status=ataSmartStatus2(fd); if (status==-1) printout(LOG_INFO,"Device: %s, not capable of SMART self-check\n",name); - else if (status==1) + else if (status==1){ + printout(LOG_CRIT, "Device: %s, FAILED SMART self-check. BACK UP DATA NOW!\n", name); printandmail(cfg->address, cfg->maildata , LOG_CRIT, "Device: %s, FAILED SMART self-check. BACK UP DATA NOW!\n", name); + } } // Check everything that depends upon SMART Data (eg, Attribute values) @@ -632,6 +630,7 @@ int ataCheckDevice(atadevices_t *drive){ while (*loc && *loc==' ') loc++; // warning message + printout(LOG_CRIT, "Device: %s, Failed SMART usage Attribute: %s.\n", name, loc); printandmail(cfg->address, cfg->maildata+1, LOG_CRIT, "Device: %s, Failed SMART usage Attribute: %s.\n", name, loc); } } @@ -680,8 +679,10 @@ int ataCheckDevice(atadevices_t *drive){ unsigned char old=cfg->selflogcount; int new=selftesterrorcount(fd, name); if (new>old){ - printandmail(cfg->address, cfg->maildata+2, LOG_CRIT, "Device: %s, Self-Test Log error count increased from %d to %d\n", + printout(LOG_CRIT, "Device: %s, Self-Test Log error count increased from %d to %d\n", name, (int)old, new); + printandmail(cfg->address, cfg->maildata+2, LOG_CRIT, "Device: %s, Self-Test Log error count increased from %d to %d\n", + name, (int)old, new); } if (new>=0) // Needed suince self-test error count may DECREASE @@ -694,8 +695,10 @@ int ataCheckDevice(atadevices_t *drive){ int old=cfg->ataerrorcount; int new=ataerrorcount(fd, name); if (new>old){ - printandmail(cfg->address, cfg->maildata+3, LOG_CRIT, "Device: %s, ATA error count increased from %d to %d\n", + printout(LOG_CRIT, "Device: %s, ATA error count increased from %d to %d\n", name, old, new); + printandmail(cfg->address, cfg->maildata+3, LOG_CRIT, "Device: %s, ATA error count increased from %d to %d\n", + name, old, new); } // this last line is probably not needed, count always increases if (new>=0)