From f970c2d3a8989904e2acf4139103e3e87dcfbaca Mon Sep 17 00:00:00 2001 From: ballen4705 <ballen4705@4ea69e1a-61f1-4043-bf83-b5c94c648137> Date: Sun, 9 Feb 2003 21:12:34 +0000 Subject: [PATCH] Added timezone info to dates string used by smartd email Directive. Added additional environment variable SMART_TFIRSTEPOCH containing integer unix epoch of SMARTD_TFIFST. Removed newline from environment variable SMART_TFIRST. git-svn-id: https://smartmontools.svn.sourceforge.net/svnroot/smartmontools/trunk@485 4ea69e1a-61f1-4043-bf83-b5c94c648137 --- sm5/smartd.8 | 19 ++++++++++++++----- sm5/smartd.c | 15 ++++++++++----- sm5/smartd.conf.5 | 19 ++++++++++++++----- sm5/smartd.cpp | 15 ++++++++++----- sm5/utility.c | 22 ++++++++++++++-------- sm5/utility.cpp | 22 ++++++++++++++-------- sm5/utility.h | 12 ++++++++---- 7 files changed, 84 insertions(+), 40 deletions(-) diff --git a/sm5/smartd.8 b/sm5/smartd.8 index 0be2424f5..0af1060ac 100644 --- a/sm5/smartd.8 +++ b/sm5/smartd.8 @@ -1,6 +1,6 @@ \# Copyright (C) 2002 Bruce Allen <smartmontools-support@lists.sourceforge.net> \# -\# $Id: smartd.8,v 1.61 2003/02/08 18:50:27 pjwilliams Exp $ +\# $Id: smartd.8,v 1.62 2003/02/09 21:12:32 ballen4705 Exp $ \# \# This program is free software; you can redistribute it and/or modify it \# under the terms of the GNU General Public License as published by the Free @@ -16,7 +16,7 @@ \# Research Center), Jack Baskin School of Engineering, University of \# California, Santa Cruz. http://ssrc.soe.ucsc.edu/ \# -.TH SMARTD 8 "$Date: 2003/02/08 18:50:27 $" "smartmontools-5.1" +.TH SMARTD 8 "$Date: 2003/02/09 21:12:32 $" "smartmontools-5.1" .SH NAME smartd \- S.M.A.R.T. Daemon .SH SYNOPSIS @@ -623,8 +623,17 @@ double quotes. .fi .B SMARTD_TFIRST is a text string giving the time and date at which the first problem -of this type was reported. Note that this text string contains space -characters and is NOT quoted. +of this type was reported. This text string contains space characters +and no newlines, and is NOT quoted. For example: +.nf +.fi +Sun Feb 9 14:58:19 2003 CST +.nf +.fi +.B SMARTD_TFIRSTEPOCH +is an integer, which is the unix epoch (number of seconds since Jan 1, +1970) for +.B SMARTD_TFIRST. The shell which is used to run PATH is system-dependent. For vanilla linux/glibc it's bash. For other systems, the man page for system (3) @@ -957,4 +966,4 @@ Please let us know if there is an on\-line source for this document. .SH CVS ID OF THIS PAGE: -$Id: smartd.8,v 1.61 2003/02/08 18:50:27 pjwilliams Exp $ +$Id: smartd.8,v 1.62 2003/02/09 21:12:32 ballen4705 Exp $ diff --git a/sm5/smartd.c b/sm5/smartd.c index 61e82a202..bdca48d3b 100644 --- a/sm5/smartd.c +++ b/sm5/smartd.c @@ -50,7 +50,7 @@ // CVS ID strings 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.109 2003/02/06 16:33:55 ballen4705 Exp $" +const char *smartd_c_cvsid="$Id: smartd.c,v 1.110 2003/02/09 21:12:33 ballen4705 Exp $" 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. @@ -116,7 +116,7 @@ void printout(int priority,char *fmt, ...){ // a warning email, or execute executable void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){ char command[2048], message[256], hostname[256], additional[256]; - char original[256], further[256], domainname[256], subject[256]; + char original[256], further[256], domainname[256], subject[256],dates[64]; int status; time_t epoch; va_list ap; @@ -197,8 +197,10 @@ void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){ (0x01)<<mail->logged); break; } - if (cfg->emailfreq>1 && mail->logged) - sprintf(original,"The original email about this issue was sent at %s\n",ctime(&(mail->firstsent))); + if (cfg->emailfreq>1 && mail->logged){ + dateandtimezoneepoch(dates, mail->firstsent); + sprintf(original,"The original email about this issue was sent at %s\n", dates); + } } snprintf(subject, 256,"SMART error (%s) detected on host: %s", whichfail[which], hostname); @@ -214,7 +216,10 @@ void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){ setenv("SMARTD_DEVICETYPE", cfg->tryata?"ata":"scsi", 1); setenv("SMARTD_MESSAGE", message, 1); setenv("SMARTD_SUBJECT", subject, 1); - setenv("SMARTD_TFIRST", ctime(&(mail->firstsent)), 1); + dateandtimezoneepoch(dates, mail->firstsent); + setenv("SMARTD_TFIRST", dates, 1); + snprintf(dates, 64,"%d", (int)mail->firstsent); + setenv("SMARTD_TFIRSTEPOCH", dates, 1); setenv("SMARTD_FAILTYPE", whichfail[which], 1); if (address) setenv("SMARTD_ADDRESS", address, 1); diff --git a/sm5/smartd.conf.5 b/sm5/smartd.conf.5 index 404c582fc..ef3f2bd8e 100644 --- a/sm5/smartd.conf.5 +++ b/sm5/smartd.conf.5 @@ -1,6 +1,6 @@ \# Copyright (C) 2002 Bruce Allen <smartmontools-support@lists.sourceforge.net> \# -\# $Id: smartd.conf.5,v 1.27 2003/02/09 16:14:31 ballen4705 Exp $ +\# $Id: smartd.conf.5,v 1.28 2003/02/09 21:12:33 ballen4705 Exp $ \# \# This program is free software; you can redistribute it and/or modify it \# under the terms of the GNU General Public License as published by the Free @@ -16,7 +16,7 @@ \# Research Center), Jack Baskin School of Engineering, University of \# California, Santa Cruz. http://ssrc.soe.ucsc.edu/ \# -.TH SMARTD.CONF 5 "$Date: 2003/02/09 16:14:31 $" "smartmontools-5.1" +.TH SMARTD.CONF 5 "$Date: 2003/02/09 21:12:33 $" "smartmontools-5.1" .SH NAME smartd.conf \- S.M.A.R.T. Monitoring Daemon Configuration File @@ -423,8 +423,17 @@ double quotes. .fi .B SMARTD_TFIRST is a text string giving the time and date at which the first problem -of this type was reported. Note that this text string contains space -characters and is NOT quoted. +of this type was reported. This text string contains space characters +and no newlines, and is NOT quoted. For example: +.nf +.fi +Sun Feb 9 14:58:19 2003 CST +.nf +.fi +.B SMARTD_TFIRSTEPOCH +is an integer, which is the unix epoch (number of seconds since Jan 1, +1970) for +.B SMARTD_TFIRST. The shell which is used to run PATH is system-dependent. For vanilla linux/glibc it's bash. For other systems, the man page for system (3) @@ -683,4 +692,4 @@ SEE ALSO: .SH CVS ID OF THIS PAGE: -$Id: smartd.conf.5,v 1.27 2003/02/09 16:14:31 ballen4705 Exp $ +$Id: smartd.conf.5,v 1.28 2003/02/09 21:12:33 ballen4705 Exp $ diff --git a/sm5/smartd.cpp b/sm5/smartd.cpp index d1f21960b..edf101f12 100644 --- a/sm5/smartd.cpp +++ b/sm5/smartd.cpp @@ -50,7 +50,7 @@ // CVS ID strings 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.109 2003/02/06 16:33:55 ballen4705 Exp $" +const char *smartd_c_cvsid="$Id: smartd.cpp,v 1.110 2003/02/09 21:12:33 ballen4705 Exp $" 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. @@ -116,7 +116,7 @@ void printout(int priority,char *fmt, ...){ // a warning email, or execute executable void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){ char command[2048], message[256], hostname[256], additional[256]; - char original[256], further[256], domainname[256], subject[256]; + char original[256], further[256], domainname[256], subject[256],dates[64]; int status; time_t epoch; va_list ap; @@ -197,8 +197,10 @@ void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){ (0x01)<<mail->logged); break; } - if (cfg->emailfreq>1 && mail->logged) - sprintf(original,"The original email about this issue was sent at %s\n",ctime(&(mail->firstsent))); + if (cfg->emailfreq>1 && mail->logged){ + dateandtimezoneepoch(dates, mail->firstsent); + sprintf(original,"The original email about this issue was sent at %s\n", dates); + } } snprintf(subject, 256,"SMART error (%s) detected on host: %s", whichfail[which], hostname); @@ -214,7 +216,10 @@ void printandmail(cfgfile *cfg, int which, int priority, char *fmt, ...){ setenv("SMARTD_DEVICETYPE", cfg->tryata?"ata":"scsi", 1); setenv("SMARTD_MESSAGE", message, 1); setenv("SMARTD_SUBJECT", subject, 1); - setenv("SMARTD_TFIRST", ctime(&(mail->firstsent)), 1); + dateandtimezoneepoch(dates, mail->firstsent); + setenv("SMARTD_TFIRST", dates, 1); + snprintf(dates, 64,"%d", (int)mail->firstsent); + setenv("SMARTD_TFIRSTEPOCH", dates, 1); setenv("SMARTD_FAILTYPE", whichfail[which], 1); if (address) setenv("SMARTD_ADDRESS", address, 1); diff --git a/sm5/utility.c b/sm5/utility.c index 75158b084..11831abaa 100644 --- a/sm5/utility.c +++ b/sm5/utility.c @@ -35,22 +35,19 @@ #include "utility.h" // Any local header files should be represented by a CVSIDX just below. -const char* utility_c_cvsid="$Id: utility.c,v 1.3 2003/01/17 12:20:24 ballen4705 Exp $" UTILITY_H_CVSID; +const char* utility_c_cvsid="$Id: utility.c,v 1.4 2003/02/09 21:12:33 ballen4705 Exp $" UTILITY_H_CVSID; + // Utility function prints date and time and timezone into a character // buffer of length>=64. All the fuss is needed to get the right // timezone info (sigh). -void dateandtimezone(char *buffer){ - time_t tval; +void dateandtimezoneepoch(char *buffer, time_t tval){ struct tm *tmval; char *timezonename; char datebuffer[64]; - // First get the time in seconds since Jan 1 1970 - tval=time(NULL); - - // Now get the time structure. We need this to determine if we - // are in daylight savings time or not. + // Get the time structure. We need this to determine if we are in + // daylight savings time or not. tmval=localtime(&tval); // Convert to an ASCII string, put in datebuffer @@ -76,6 +73,15 @@ void dateandtimezone(char *buffer){ return; } +// Date and timezone gets printed into string pointed to by buffer +void dateandtimezone(char *buffer){ + + // Get the epoch (time in seconds since Jan 1 1970) + time_t tval=time(NULL); + + dateandtimezoneepoch(buffer, tval); + return; +} // These are two utility functions for printing CVS IDs. Massagecvs() // returns distance that it has moved ahead in the input string diff --git a/sm5/utility.cpp b/sm5/utility.cpp index edcc2811b..8b3ad1e9c 100644 --- a/sm5/utility.cpp +++ b/sm5/utility.cpp @@ -35,22 +35,19 @@ #include "utility.h" // Any local header files should be represented by a CVSIDX just below. -const char* utility_c_cvsid="$Id: utility.cpp,v 1.3 2003/01/17 12:20:24 ballen4705 Exp $" UTILITY_H_CVSID; +const char* utility_c_cvsid="$Id: utility.cpp,v 1.4 2003/02/09 21:12:33 ballen4705 Exp $" UTILITY_H_CVSID; + // Utility function prints date and time and timezone into a character // buffer of length>=64. All the fuss is needed to get the right // timezone info (sigh). -void dateandtimezone(char *buffer){ - time_t tval; +void dateandtimezoneepoch(char *buffer, time_t tval){ struct tm *tmval; char *timezonename; char datebuffer[64]; - // First get the time in seconds since Jan 1 1970 - tval=time(NULL); - - // Now get the time structure. We need this to determine if we - // are in daylight savings time or not. + // Get the time structure. We need this to determine if we are in + // daylight savings time or not. tmval=localtime(&tval); // Convert to an ASCII string, put in datebuffer @@ -76,6 +73,15 @@ void dateandtimezone(char *buffer){ return; } +// Date and timezone gets printed into string pointed to by buffer +void dateandtimezone(char *buffer){ + + // Get the epoch (time in seconds since Jan 1 1970) + time_t tval=time(NULL); + + dateandtimezoneepoch(buffer, tval); + return; +} // These are two utility functions for printing CVS IDs. Massagecvs() // returns distance that it has moved ahead in the input string diff --git a/sm5/utility.h b/sm5/utility.h index 7f8e2cbec..0ebc7936c 100644 --- a/sm5/utility.h +++ b/sm5/utility.h @@ -26,13 +26,17 @@ #define __UTILITY_H_ #ifndef UTILITY_H_CVSID -#define UTILITY_H_CVSID "$Id: utility.h,v 1.3 2003/01/17 12:20:24 ballen4705 Exp $\n" +#define UTILITY_H_CVSID "$Id: utility.h,v 1.4 2003/02/09 21:12:34 ballen4705 Exp $\n" #endif -// Utility function prints date and time and timezone into a character -// buffer of length>=64. All the fuss is needed to get the right -// timezone info (sigh). +// Utility function prints current date and time and timezone into a +// character buffer of length>=64. All the fuss is needed to get the +// right timezone info (sigh). void dateandtimezone(char *buffer); +// Same, but for time defined by epoch tval +void dateandtimezoneepoch(char *buffer, time_t tval); + + // utility function for printing out CVS strings #define CVSMAXLEN 512 -- GitLab