Skip to content
Snippets Groups Projects
Commit 988a7b0a authored by ballen4705's avatar ballen4705
Browse files

Improved email message format; eliminated un-necessary shell command

(echo) from system() command argument.


git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@253 4ea69e1a-61f1-4043-bf83-b5c94c648137
parent 5420e733
Branches
No related tags found
No related merge requests found
39
40
......@@ -45,7 +45,7 @@
// CVS ID strings
extern const char *CVSid1, *CVSid2;
const char *CVSid6="$Id: smartd.c,v 1.60 2002/11/12 22:39:21 ballen4705 Exp $"
const char *CVSid6="$Id: smartd.c,v 1.61 2002/11/13 07:39:50 ballen4705 Exp $"
CVSID1 CVSID2 CVSID3 CVSID4 CVSID7;
// global variable used for control of printing, passing arguments, etc.
......@@ -90,7 +90,7 @@ void printout(int priority,char *fmt, ...){
// If address is null, this just prints a warning message. But if
// address is non-null then send and log a warning email.
void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){
char command[1024], message[256], hostname[256];
char command[2048], message[256], hostname[256];
int status;
va_list ap;
......@@ -104,10 +104,11 @@ void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){
mail->logged++;
mail->lastsent=time(NULL);
// get system host name
if (gethostname(hostname, 256)){
// get system host name (not null terminated if length=MAX)
if (gethostname(hostname, 256))
sprintf(hostname,"Unknown host");
}
else
hostname[255]='\0';
// print warning string into message
va_start(ap, fmt);
......@@ -115,12 +116,24 @@ void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){
va_end(ap);
// now construct a command to send this as EMAIL, and issue it.
snprintf(command, 2048, "mail -s '%s: SMART errors detected' %s > /dev/null 2> /dev/null << \"ENDMAIL\"\n"
"This email was generated by the smartd daemon running on machine:\n"
"%s\n"
"The following warning/error was logged by the smartd daemon:\n"
"%s"
"Further details can be found in the machine's syslog (/var/log/messages).\n"
"You can also use the smartctl utility for further investigation.\n"
"No additional email messages about this problem will be sent.\n"
"ENDMAIL\n",
hostname, address, hostname, message);
#if (0)
snprintf(command,1024, "echo '%s' | mail -s '%s: smartd detected SMART errors' %s > /dev/null 2> /dev/null",
message, hostname, address);
status=system(command);
#endif
status=system(command);
if (WEXITSTATUS(status))
printout(LOG_CRIT,"Email warning message to %s failed (exit status %d)\n",address,status);
printout(LOG_CRIT,"Email warning message to %s failed (32-bit exit status: %d)\n",address,status);
else
printout(LOG_INFO,"Email warning message sent to %s\n",address);
......
......@@ -45,7 +45,7 @@
// CVS ID strings
extern const char *CVSid1, *CVSid2;
const char *CVSid6="$Id: smartd.cpp,v 1.60 2002/11/12 22:39:21 ballen4705 Exp $"
const char *CVSid6="$Id: smartd.cpp,v 1.61 2002/11/13 07:39:50 ballen4705 Exp $"
CVSID1 CVSID2 CVSID3 CVSID4 CVSID7;
// global variable used for control of printing, passing arguments, etc.
......@@ -90,7 +90,7 @@ void printout(int priority,char *fmt, ...){
// If address is null, this just prints a warning message. But if
// address is non-null then send and log a warning email.
void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){
char command[1024], message[256], hostname[256];
char command[2048], message[256], hostname[256];
int status;
va_list ap;
......@@ -104,10 +104,11 @@ void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){
mail->logged++;
mail->lastsent=time(NULL);
// get system host name
if (gethostname(hostname, 256)){
// get system host name (not null terminated if length=MAX)
if (gethostname(hostname, 256))
sprintf(hostname,"Unknown host");
}
else
hostname[255]='\0';
// print warning string into message
va_start(ap, fmt);
......@@ -115,12 +116,24 @@ void printandmail(char *address, mailinfo *mail, int priority, char *fmt, ...){
va_end(ap);
// now construct a command to send this as EMAIL, and issue it.
snprintf(command, 2048, "mail -s '%s: SMART errors detected' %s > /dev/null 2> /dev/null << \"ENDMAIL\"\n"
"This email was generated by the smartd daemon running on machine:\n"
"%s\n"
"The following warning/error was logged by the smartd daemon:\n"
"%s"
"Further details can be found in the machine's syslog (/var/log/messages).\n"
"You can also use the smartctl utility for further investigation.\n"
"No additional email messages about this problem will be sent.\n"
"ENDMAIL\n",
hostname, address, hostname, message);
#if (0)
snprintf(command,1024, "echo '%s' | mail -s '%s: smartd detected SMART errors' %s > /dev/null 2> /dev/null",
message, hostname, address);
status=system(command);
#endif
status=system(command);
if (WEXITSTATUS(status))
printout(LOG_CRIT,"Email warning message to %s failed (exit status %d)\n",address,status);
printout(LOG_CRIT,"Email warning message to %s failed (32-bit exit status: %d)\n",address,status);
else
printout(LOG_INFO,"Email warning message sent to %s\n",address);
......
......@@ -29,7 +29,7 @@ Packager: Bruce Allen <smartmontools-support@lists.sourceforge.net>
# http://ftp1.sourceforge.net/smartmontools/smartmontools-%{version}-%{release}.tar.gz
# CVS ID of this file is:
# $Id: smartmontools.spec,v 1.58 2002/11/12 22:42:11 ballen4705 Exp $
# $Id: smartmontools.spec,v 1.59 2002/11/13 07:39:50 ballen4705 Exp $
# Copyright (C) 2002 Bruce Allen <smartmontools-support@lists.sourceforge.net>
# Home page: http://smartmontools.sourceforge.net/
......@@ -233,6 +233,11 @@ fi
%define date %(echo `LC_ALL="C" date +"%a %b %d %Y"`)
%changelog
* Wed Nov 13 2002 Bruce Allen <smartmontools-support@lists.sourceforge.net>
- Added a new smartd configuration file Directive: -M ADDRESS.
This sends a single warning email to ADDRESS for failures or
errors detected with the -c, -L, -l, or -f Directives.
* Mon Nov 11 2002 Bruce Allen <smartmontools-support@lists.sourceforge.net>
- Modified perror() statements in atacmds.c so that printout for SMART
commands errors is properly suppressed or queued depending upon users
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment