00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef __DCLOG_H__
00042 #define __DCLOG_H__
00043
00044
00045 #include <stdio.h>
00046 #include <time.h>
00047
00048
00049 #include <common-types.h>
00050
00051
00052 #define DCLOG_ALARM 0
00053 #define DCLOG_ERROR 1
00054 #define DCLOG_WARNING 2
00055 #define DCLOG_INFO 3
00056 #define DCLOG_DEBUG 4
00057 #define DCLOG_PROFILE 5
00058
00059
00060 #define DCLOG_FN_LEN 1024
00061
00063 #define DCLOG_TS_FMT_LEN 32
00064
00066 #define DCLOG_TS_FMT_DEFAULT ".%d"
00067
00069 #define DCLOG_MAX_ALARM_SIZE 4096
00070
00071
00081 typedef struct {
00082
00083 FILE *fp;
00084 char *fn;
00085
00086 char *mailhost;
00087 char *to;
00088 char *from;
00089 char spool[256];
00090
00091 UCHAR lev;
00092 UCHAR features;
00093
00094 char ts_fmt[DCLOG_TS_FMT_LEN];
00095
00096 struct tm *prev_date;
00097
00098 time_t oldtime[1000];
00099 ULONG count[1000];
00100
00101 int limit_size;
00102 int max_file_size;
00103
00104 } DCLog;
00105
00106 static const char DCLOG_MAILHOST[] = "localhost";
00107 static const char DCLOG_TO[] = "root@localhost";
00108 static const char DCLOG_FROM[] = "localhost";
00109 static const char DCLOG_PROG[] = "dclog";
00110 static const char DCLOG_SPOOL[] = "/var/spool/alarmd";
00111
00112
00113
00114
00115
00116
00117 DCLog *NewDCLog( void );
00118 UCHAR DestroyDCLog( DCLog *dclog );
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128 char DCLogLevelToNum( const char *str );
00129 const char *DCLogLevelToString( const char lev );
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 UCHAR DCLogSetHeader( DCLog *dclog, const UCHAR val );
00140 UCHAR DCLogSetLevel( DCLog *dclog, const UCHAR lev );
00141 UCHAR DCLogSetMailServer( DCLog *dclog, const char *mailhost );
00142 UCHAR DCLogSetMaxFileSize( DCLog *dclog, const int size );
00143 UCHAR DCLogSetPageServer( DCLog *dclog, const char *server );
00144 UCHAR DCLogSetPrintLevel( DCLog *dclog, const UCHAR val );
00145 UCHAR DCLogSetProgram( DCLog *dclog, const char *prog );
00146 UCHAR DCLogSetSpool( DCLog *dclog, const char *spool );
00147 UCHAR DCLogSetUniqueByDay( DCLog *dclog, const UCHAR val );
00148 UCHAR DCLogSetTimestampFormat( DCLog *dclog, char *const ts_fmt );
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 UCHAR DCLogOpen( DCLog *dclog, const char *fn, const char *mode );
00159 UCHAR DCLogClose( DCLog *dclog );
00160
00161 UCHAR DCLogAlarm( DCLog *dclog, const char *code, const char *syn,
00162 const char *fmt, ... );
00163 UCHAR DCLogWrite( DCLog *dclog, const UCHAR lev, const char *fmt, ... );
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 UCHAR DCLogCanLog( const DCLog *dclog );
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 UCHAR DCLogSmtpSend( const char *mailhost, const char *to, const char *from,
00185 const char *subject, const char *msg );
00186 UCHAR DCLogSmtpShutdown( const int socket, const int retval );
00187
00188
00189
00190
00191
00192
00193 #endif // #ifndef __DCLOG_H__