56 |
static int check_timeout(Process_T); |
static int check_timeout(Process_T); |
57 |
static int check_checksum(Process_T); |
static int check_checksum(Process_T); |
58 |
static int checksum_helper(Process_T, char *, char *); |
static int checksum_helper(Process_T, char *, char *); |
59 |
|
static int check_timestamp(Process_T, Timestamp_T, char *); |
60 |
static void connection_timeout(int); |
static void connection_timeout(int); |
61 |
static void reset_resource_counter(Process_T); |
static void reset_resource_counter(Process_T); |
62 |
static void vlog(char * report, int n, Process_T p, char *m,...); |
static void vlog(char * report, int n, Process_T p, char *m,...); |
63 |
|
static int compare_value(int, int, int); |
64 |
|
|
65 |
/** |
/** |
66 |
* Check that all processes in the process list are running and |
* Check that all processes in the process list are running and |
119 |
|
|
120 |
Port_T pp; |
Port_T pp; |
121 |
Resource_T pr; |
Resource_T pr; |
122 |
|
Timestamp_T tl; |
123 |
pid_t pid= -1; |
pid_t pid= -1; |
124 |
sigset_t ns,os; |
sigset_t ns,os; |
125 |
char report[STRLEN]; |
char report[STRLEN]; |
172 |
if ( !check_resources(p, pr, report) ) { |
if ( !check_resources(p, pr, report) ) { |
173 |
|
|
174 |
switch (pr->action) { |
switch (pr->action) { |
175 |
case RESOURCE_ACTION_ALERT: |
case ACTION_ALERT: |
176 |
smtp_alert_resource(p, "Reason: %s\n", report); |
smtp_alert_resource(p, "Reason: %s\n", report); |
177 |
|
|
178 |
/* We are also interested in other alerts/stops/restarts! */ |
/* We are also interested in other alerts/stops/restarts! */ |
179 |
pr->cycle=0; |
pr->cycle=0; |
180 |
break; |
break; |
181 |
|
|
182 |
case RESOURCE_ACTION_STOP: |
case ACTION_STOP: |
183 |
|
|
184 |
do_stop(p, "Reason: %s\n", report); |
do_stop(p, "Reason: %s\n", report); |
185 |
reset_resource_counter(p); |
reset_resource_counter(p); |
186 |
goto reinstall; |
goto reinstall; |
187 |
|
|
188 |
case RESOURCE_ACTION_RESTART: |
case ACTION_RESTART: |
189 |
|
|
190 |
do_restart(p, "Reason: %s\n", report); |
do_restart(p, "Reason: %s\n", report); |
191 |
reset_resource_counter(p); |
reset_resource_counter(p); |
214 |
|
|
215 |
} |
} |
216 |
|
|
217 |
|
for( tl= p->timestamplist; tl; tl= tl->next ) { |
218 |
|
|
219 |
|
if ( !check_timestamp(p, tl, report) ) { |
220 |
|
|
221 |
|
switch (tl->action) { |
222 |
|
case ACTION_ALERT: |
223 |
|
smtp_alert_timestamp(p, "Reason: %s\n", report); |
224 |
|
break; /* continue */ |
225 |
|
|
226 |
|
case ACTION_STOP: |
227 |
|
|
228 |
|
do_stop(p, "Reason: %s\n", report); |
229 |
|
goto reinstall; |
230 |
|
|
231 |
|
case ACTION_RESTART: |
232 |
|
|
233 |
|
do_restart(p, "Reason: %s\n", report); |
234 |
|
goto reinstall; |
235 |
|
|
236 |
|
default: |
237 |
|
|
238 |
|
log("'%s' Unknow timestamp failure action.\n", p->name); |
239 |
|
break; |
240 |
|
|
241 |
|
} |
242 |
|
|
243 |
|
} |
244 |
|
|
245 |
|
} |
246 |
|
|
247 |
/* Test each host:port and protocol in the process's portlist */ |
/* Test each host:port and protocol in the process's portlist */ |
248 |
for(pp= p->portlist; pp; pp= pp->next) { |
for(pp= p->portlist; pp; pp= pp->next) { |
249 |
|
|
601 |
|
|
602 |
switch (pr->resource_id) { |
switch (pr->resource_id) { |
603 |
case RESOURCE_ID_CPU_PERCENT: |
case RESOURCE_ID_CPU_PERCENT: |
604 |
if ( compare_resource(pi->cpu_percent, pr) ) { |
if ( compare_value(pr->operator, pi->cpu_percent, pr->limit) ) { |
605 |
|
|
606 |
vlog(report, STRLEN, p, |
vlog(report, STRLEN, p, |
607 |
"cpu usage of %.1f%% matches resource limit [cpu usage%s%.1f%%]", |
"cpu usage of %.1f%% matches resource limit [cpu usage%s%.1f%%]", |
622 |
break; |
break; |
623 |
|
|
624 |
case RESOURCE_ID_MEM_PERCENT: |
case RESOURCE_ID_MEM_PERCENT: |
625 |
if ( compare_resource(pi->mem_percent, pr) ) { |
if ( compare_value(pr->operator, pi->mem_percent, pr->limit) ) { |
626 |
|
|
627 |
vlog(report, STRLEN, p, |
vlog(report, STRLEN, p, |
628 |
"mem usage of %.1f%% matches resource limit [mem usage%s%.1f%%]", |
"mem usage of %.1f%% matches resource limit [mem usage%s%.1f%%]", |
644 |
|
|
645 |
case RESOURCE_ID_MEM_KBYTE: |
case RESOURCE_ID_MEM_KBYTE: |
646 |
|
|
647 |
if ( compare_resource(pi->mem_kbyte, pr) ) { |
if ( compare_value(pr->operator, pi->mem_kbyte, pr->limit) ) { |
648 |
|
|
649 |
vlog(report, STRLEN, p, |
vlog(report, STRLEN, p, |
650 |
"mem amount of %ldkB matches resource limit [mem amount%s%ldkB]", |
"mem amount of %ldkB matches resource limit [mem amount%s%ldkB]", |
666 |
|
|
667 |
case RESOURCE_ID_LOAD1: |
case RESOURCE_ID_LOAD1: |
668 |
|
|
669 |
if ( compare_resource((int) (Run.loadavg[0]*10.0), pr) ) { |
if ( compare_value(pr->operator, (int)(Run.loadavg[0]*10.0), pr->limit) ) { |
670 |
|
|
671 |
vlog(report, STRLEN, p, |
vlog(report, STRLEN, p, |
672 |
"loadavg(1min) of %.1f matches resource limit " |
"loadavg(1min) of %.1f matches resource limit " |
689 |
|
|
690 |
case RESOURCE_ID_LOAD5: |
case RESOURCE_ID_LOAD5: |
691 |
|
|
692 |
if ( compare_resource((int) (Run.loadavg[1]*10.0), pr) ) { |
if ( compare_value(pr->operator, (int)(Run.loadavg[1]*10.0), pr->limit) ) { |
693 |
|
|
694 |
vlog(report, STRLEN, p, |
vlog(report, STRLEN, p, |
695 |
"loadavg(5min) of %.1f matches resource limit " |
"loadavg(5min) of %.1f matches resource limit " |
712 |
|
|
713 |
case RESOURCE_ID_LOAD15: |
case RESOURCE_ID_LOAD15: |
714 |
|
|
715 |
if ( compare_resource((int) (Run.loadavg[2]*10.0), pr) ) { |
if ( compare_value(pr->operator, (int)(Run.loadavg[2]*10.0), pr->limit) ) { |
716 |
|
|
717 |
vlog(report, STRLEN, p, |
vlog(report, STRLEN, p, |
718 |
"loadavg(15min) of %.1f matches resource limit " |
"loadavg(15min) of %.1f matches resource limit " |
922 |
|
|
923 |
|
|
924 |
/** |
/** |
925 |
|
* Returns TRUE if the timestamp test succeded, otherwise FALSE |
926 |
|
*/ |
927 |
|
static int check_timestamp(Process_T p, Timestamp_T t, char *report) { |
928 |
|
|
929 |
|
time_t now; |
930 |
|
time_t timestamp; |
931 |
|
|
932 |
|
if( (int)time(&now) == -1 ) { |
933 |
|
vlog(report, STRLEN, p, "can't get actual time"); |
934 |
|
return FALSE; |
935 |
|
} |
936 |
|
|
937 |
|
if ( !(timestamp= get_timestamp(t->pathname, S_IFDIR|S_IFREG)) ) { |
938 |
|
vlog(report, STRLEN, p, "can't get timestamp for %s", t->pathname); |
939 |
|
return FALSE; |
940 |
|
} |
941 |
|
|
942 |
|
if( compare_value(t->operator, (int)(now - timestamp), t->time) ) { |
943 |
|
vlog(report, STRLEN, p, "timestamp test failed for %s", t->pathname); |
944 |
|
return FALSE; |
945 |
|
} |
946 |
|
|
947 |
|
if(Run.debug) |
948 |
|
log("'%s' timestamp test passed for %s\n", p->name, t->pathname); |
949 |
|
|
950 |
|
return TRUE; |
951 |
|
|
952 |
|
} |
953 |
|
|
954 |
|
|
955 |
|
/** |
956 |
* Signal handler for connection timeout |
* Signal handler for connection timeout |
957 |
*/ |
*/ |
958 |
static void connection_timeout(int sig) { |
static void connection_timeout(int sig) { |
985 |
|
|
986 |
free(tmp); |
free(tmp); |
987 |
} |
} |
988 |
|
|
989 |
|
|
990 |
|
/** |
991 |
|
* Comparison of values. Returns TRUE if comparison matches, otherwise |
992 |
|
* FALSE. |
993 |
|
*/ |
994 |
|
static int compare_value(int operator, int left, int right) { |
995 |
|
|
996 |
|
switch (operator) { |
997 |
|
|
998 |
|
case OPERATOR_GREATER: |
999 |
|
|
1000 |
|
if( left > right ) |
1001 |
|
return TRUE; |
1002 |
|
break; |
1003 |
|
|
1004 |
|
case OPERATOR_LESS: |
1005 |
|
|
1006 |
|
if( left < right ) |
1007 |
|
return TRUE; |
1008 |
|
break; |
1009 |
|
|
1010 |
|
case OPERATOR_EQUAL: |
1011 |
|
|
1012 |
|
if( left == right ) |
1013 |
|
return TRUE; |
1014 |
|
break; |
1015 |
|
|
1016 |
|
case OPERATOR_NOTEQUAL: |
1017 |
|
|
1018 |
|
if( left != right ) |
1019 |
|
return TRUE; |
1020 |
|
break; |
1021 |
|
|
1022 |
|
default: |
1023 |
|
error("Unknow comparison operator\n"); |
1024 |
|
return FALSE; |
1025 |
|
|
1026 |
|
} |
1027 |
|
|
1028 |
|
return FALSE; |
1029 |
|
|
1030 |
|
} |
1031 |
|
|