"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/validate.c" between
monit-5.27.2.tar.gz and monit-5.28.0.tar.gz

About: Monit is a utility for managing and monitoring processes, files, directories and filesystems (with automatic error recovery).

validate.c  (monit-5.27.2):validate.c  (monit-5.28.0)
skipping to change at line 154 skipping to change at line 154
ASSERT(s); ASSERT(s);
ASSERT(p); ASSERT(p);
volatile int retry_count = p->retry; volatile int retry_count = p->retry;
volatile State_Type rv = State_Succeeded; volatile State_Type rv = State_Succeeded;
char buf[STRLEN]; char buf[STRLEN];
char report[1024] = {}; char report[1024] = {};
retry: retry:
TRY TRY
{ {
Socket_test(p); Socket_test(p);
rv = State_Succeeded; rv = p->check_invers ? State_Failed : State_Succeeded;
DEBUG("'%s' succeeded testing protocol [%s] at %s [response time DEBUG("'%s' succeeded testing protocol [%s] at %s [response time
%s]\n", s->name, p->protocol->name, Util_portDescription(p, buf, sizeof(buf)), %s]\n", s->name, p->protocol->name, Util_portDescription(p, buf, sizeof(buf)),
Convert_time2str(p->response, (char[11]){})); Convert_time2str(p->responsetime.current, (char[11]){}));
} }
ELSE ELSE
{ {
rv = State_Failed; rv = p->check_invers ? State_Succeeded : State_Failed;
snprintf(report, sizeof(report), "failed protocol test [%s] at % s -- %s", p->protocol->name, Util_portDescription(p, buf, sizeof(buf)), Exceptio n_frame.message); snprintf(report, sizeof(report), "failed protocol test [%s] at % s -- %s", p->protocol->name, Util_portDescription(p, buf, sizeof(buf)), Exceptio n_frame.message);
} }
END_TRY; END_TRY;
if (rv == State_Failed) { if ((rv == State_Failed && ! p->check_invers) || (rv == State_Succeeded && p->check_invers)) {
if (retry_count-- > 1) { if (retry_count-- > 1) {
Log_warning("'%s' %s (attempt %d/%d)\n", s->name, report , p->retry - retry_count, p->retry); Log_warning("'%s' %s (attempt %d/%d)\n", s->name, report , p->retry - retry_count, p->retry);
goto retry; goto retry;
} }
Event_post(s, Event_Connection, State_Failed, p->action, "%s", r eport); Event_post(s, Event_Connection, p->check_invers ? State_Succeede d : State_Failed, p->action, "%s", report);
} else { } else {
Event_post(s, Event_Connection, State_Succeeded, p->action, "con Event_post(s, Event_Connection, p->check_invers ? State_Failed :
nection succeeded to %s", Util_portDescription(p, buf, sizeof(buf))); State_Succeeded, p->action, "connection succeeded to %s", Util_portDescription(
p, buf, sizeof(buf)));
}
if (p->responsetime.limit > -1.) {
if (Util_evalDoubleQExpression(p->responsetime.operator, p->resp
onsetime.current, p->responsetime.limit)) {
rv = State_Failed;
Event_post(s, Event_Speed, State_Failed, p->action, "res
ponse time %s doesn't match limit [time %s %s]", Convert_time2str(p->responsetim
e.current, (char[11]){}), operatorshortnames[p->responsetime.operator], Convert_
time2str(p->responsetime.limit, (char[11]){}));
} else {
Event_post(s, Event_Speed, State_Failed, p->action, "res
ponse time %s matches limit [time %s %s]", Convert_time2str(p->responsetime.curr
ent, (char[11]){}), operatorshortnames[p->responsetime.operator], Convert_time2s
tr(p->responsetime.limit, (char[11]){}));
}
} }
if (p->target.net.ssl.options.flags && p->target.net.ssl.certificate.val idDays >= 0 && p->target.net.ssl.certificate.minimumDays > 0) { if (p->target.net.ssl.options.flags && p->target.net.ssl.certificate.val idDays >= 0 && p->target.net.ssl.certificate.minimumDays > 0) {
if (p->target.net.ssl.certificate.validDays < p->target.net.ssl. certificate.minimumDays) { if (p->target.net.ssl.certificate.validDays < p->target.net.ssl. certificate.minimumDays) {
Event_post(s, Event_Timestamp, State_Failed, p->action, "certificate expiry in %d days matches check limit [valid > %d days]", p->target .net.ssl.certificate.validDays, p->target.net.ssl.certificate.minimumDays); Event_post(s, Event_Timestamp, State_Failed, p->action, "certificate expiry in %d days matches check limit [valid > %d days]", p->target .net.ssl.certificate.validDays, p->target.net.ssl.certificate.minimumDays);
rv = State_Failed; rv = State_Failed;
} else { } else {
Event_post(s, Event_Timestamp, State_Succeeded, p->actio n, "certificate valid days test succeeded [valid for %d days]", p->target.net.ss l.certificate.validDays); Event_post(s, Event_Timestamp, State_Succeeded, p->actio n, "certificate valid days test succeeded [valid for %d days]", p->target.net.ss l.certificate.validDays);
} }
} }
return rv; return rv;
skipping to change at line 1441 skipping to change at line 1449
/** /**
* Returns true if scheduled action was performed * Returns true if scheduled action was performed
*/ */
static bool _doScheduledAction(Service_T s) { static bool _doScheduledAction(Service_T s) {
int rv = false; int rv = false;
Action_Type action = s->doaction; Action_Type action = s->doaction;
if (action != Action_Ignored) { if (action != Action_Ignored) {
rv = control_service(s->name, action); rv = control_service(s->name, action);
Event_post(s, Event_Action, State_Changed, s->action_ACTION, "%s action %s", actionnames[action], rv ? "done" : "failed"); Event_post(s, Event_Action, State_Changed, s->action_ACTION, "%s action %s", actionnames[action], rv ? "done" : "failed");
FREE(s->token);
} }
return rv; return rv;
} }
/* ---------------------------------------------------------------- Public */ /* ---------------------------------------------------------------- Public */
/** /**
* This function contains the main check machinery for monit. The * This function contains the main check machinery for monit. The
* validate function check services in the service list to see if * validate function check services in the service list to see if
* they will pass all defined tests. * they will pass all defined tests.
skipping to change at line 1883 skipping to change at line 1890
* @return false if there was an error otherwise true * @return false if there was an error otherwise true
*/ */
State_Type check_remote_host(Service_T s) { State_Type check_remote_host(Service_T s) {
ASSERT(s); ASSERT(s);
State_Type rv = State_Succeeded; State_Type rv = State_Succeeded;
Icmp_T last_ping = NULL; Icmp_T last_ping = NULL;
/* Test each icmp type in the service's icmplist */ /* Test each icmp type in the service's icmplist */
for (Icmp_T icmp = s->icmplist; icmp; icmp = icmp->next) { for (Icmp_T icmp = s->icmplist; icmp; icmp = icmp->next) {
switch (icmp->type) { switch (icmp->type) {
case ICMP_ECHO: case ICMP_ECHO:
icmp->response = icmp_echo(s->path, icmp->family icmp->responsetime.current = icmp_echo(s->path,
, &(icmp->outgoing), icmp->size, icmp->timeout, icmp->count); icmp->family, &(icmp->outgoing), icmp->size, icmp->timeout, icmp->count);
if (icmp->response == -2) { if (icmp->responsetime.current == -2) {
icmp->is_available = Connection_Init; icmp->is_available = Connection_Init;
#ifdef SOLARIS #ifdef SOLARIS
DEBUG("'%s' ping test skipped -- the mon DEBUG("'%s' ping test skipped -- the mon
it user has no permission to create raw socket, please add net_icmpaccess privil it user has no permission to create raw socket, please add net_icmpaccess privil
ege\n", s->name); ege or run monit as root\n", s->name);
#elif defined LINUX
DEBUG("'%s' ping test skipped -- the mon
it user has no permission to create raw socket, please add CAP_NET_RAW capabilit
y or run monit as root\n", s->name);
#else #else
DEBUG("'%s' ping test skipped -- the mon it user has no permission to create raw socket, please run monit as root\n", s-> name); DEBUG("'%s' ping test skipped -- the mon it user has no permission to create raw socket, please run monit as root\n", s-> name);
#endif #endif
} else if (icmp->response == -1) { } else if (icmp->responsetime.current == -1) {
rv = State_Failed; rv = icmp->check_invers ? State_Succeede
d : State_Failed;
icmp->is_available = Connection_Failed; icmp->is_available = Connection_Failed;
Event_post(s, Event_Icmp, State_Failed, icmp->action, "ping test failed"); Event_post(s, Event_Icmp, rv, icmp->acti on, "ping test failed");
} else { } else {
rv = icmp->check_invers ? State_Failed : State_Succeeded;
icmp->is_available = Connection_Ok; icmp->is_available = Connection_Ok;
Event_post(s, Event_Icmp, State_Succeede Event_post(s, Event_Icmp, rv, icmp->acti
d, icmp->action, "ping test succeeded [response time %s]", Convert_time2str(icmp on, "ping test succeeded [response time %s]", Convert_time2str(icmp->responsetim
->response, (char[11]){})); e.current, (char[11]){}));
// Check response time
if (icmp->responsetime.limit > -1.) {
if (Util_evalDoubleQExpression(i
cmp->responsetime.operator, icmp->responsetime.current, icmp->responsetime.limit
)) {
rv = State_Failed;
Event_post(s, Event_Spee
d, State_Failed, icmp->action, "response time %s doesn't match limit [time %s %s
]", Convert_time2str(icmp->responsetime.current, (char[11]){}), operatorshortnam
es[icmp->responsetime.operator], Convert_time2str(icmp->responsetime.limit, (cha
r[11]){}));
} else {
Event_post(s, Event_Spee
d, State_Failed, icmp->action, "response time %s matches limit [time %s %s]", Co
nvert_time2str(icmp->responsetime.current, (char[11]){}), operatorshortnames[icm
p->responsetime.operator], Convert_time2str(icmp->responsetime.limit, (char[11])
{}));
}
}
} }
last_ping = icmp; last_ping = icmp;
break; break;
default: default:
Log_error("'%s' error -- unknown ICMP type: [%d] \n", s->name, icmp->type); Log_error("'%s' error -- unknown ICMP type: [%d] \n", s->name, icmp->type);
return State_Failed; return State_Failed;
} }
} }
/* If we could not ping the host we assume it's down and do not continue to check any port connections */ /* If we could not ping the host we assume it's down and do not continue to check any port connections */
if (last_ping && last_ping->is_available == Connection_Failed && s->port list) { if (last_ping && last_ping->is_available == Connection_Failed && s->port list) {
skipping to change at line 1938 skipping to change at line 1958
if (_checkUptime(s, Time_now() - systeminfo.booted) == State_Failed) if (_checkUptime(s, Time_now() - systeminfo.booted) == State_Failed)
rv = State_Failed; rv = State_Failed;
if ( systeminfo.statisticsAvailable & Statistics_FiledescriptorsPerSyste m ) { if ( systeminfo.statisticsAvailable & Statistics_FiledescriptorsPerSyste m ) {
if (_checkSystemFiledescriptors(s) == State_Failed) if (_checkSystemFiledescriptors(s) == State_Failed)
rv = State_Failed; rv = State_Failed;
} }
return rv; return rv;
} }
State_Type check_net(Service_T s) { State_Type check_net(Service_T s) {
volatile bool havedata = true;
volatile State_Type rv = State_Succeeded; volatile State_Type rv = State_Succeeded;
volatile bool havedata = true;
// Get link statistics
TRY TRY
{ {
Link_update(s->inf.net->stats); Link_update(s->inf.net->stats);
} }
ELSE ELSE
{ {
havedata = false; havedata = false;
for (LinkStatus_T link = s->linkstatuslist; link; link = link->n for (LinkStatus_T link = s->linkstatuslist; link; link = link->n
ext) ext) {
Event_post(s, Event_Link, State_Failed, link->action, "l rv = link->check_invers ? State_Succeeded : State_Failed
ink data collection failed -- %s", Exception_frame.message); ;
Event_post(s, Event_Link, link->check_invers ? State_Suc
ceeded : State_Failed, link->action, "link data collection failed -- %s", Except
ion_frame.message);
}
} }
END_TRY; END_TRY;
if (! havedata)
return State_Failed; // Terminate test if no data are available
// State // State
if (! Link_getState(s->inf.net->stats)) { if (! havedata) {
for (LinkStatus_T link = s->linkstatuslist; link; link = link->n return s->inverseStatus ? State_Succeeded : State_Failed; // No
ext) data, event handled in the TRY-ELSE loop already, terminate remaining tests
Event_post(s, Event_Link, State_Failed, link->action, "l } else if (! Link_getState(s->inf.net->stats)) {
ink down"); for (LinkStatus_T link = s->linkstatuslist; link; link = link->n
return State_Failed; // Terminate test if the link is down ext) {
Event_post(s, Event_Link, link->check_invers ? State_Suc
ceeded : State_Failed, link->action, "link down");
}
return s->inverseStatus ? State_Succeeded : State_Failed; // Lin
k is down, terminate remaining tests
} else { } else {
for (LinkStatus_T link = s->linkstatuslist; link; link = link->n ext) for (LinkStatus_T link = s->linkstatuslist; link; link = link->n ext)
Event_post(s, Event_Link, State_Succeeded, link->action, "link up"); Event_post(s, Event_Link, link->check_invers ? State_Fai led : State_Succeeded, link->action, "link up");
} }
// Link errors if (! s->inverseStatus) {
long long oerrors = Link_getErrorsOutPerSecond(s->inf.net->stats); //FIXME: these tests share the same class (Event_Link), so if "l
for (LinkStatus_T link = s->linkstatuslist; link; link = link->next) { ink up" test is set, it would set the state to failure, but these tests will res
if (oerrors > 0) { et it back to success. When we'll add more event types,
rv = State_Failed; // we shoud assign a new type for link in/out errors and t
Event_post(s, Event_Link, State_Failed, link->action, "% hen we can perform these tests even if "link up" is set
lld upload errors detected", oerrors);
} else { // Link errors
Event_post(s, Event_Link, State_Succeeded, link->action, long long oerrors = Link_getErrorsOutPerSecond(s->inf.net->stats
"upload errors check succeeded"); );
for (LinkStatus_T link = s->linkstatuslist; link; link = link->n
ext) {
if (oerrors > 0) {
rv = State_Failed;
Event_post(s, Event_Link, State_Failed, link->ac
tion, "%lld upload errors detected", oerrors);
} else {
Event_post(s, Event_Link, State_Succeeded, link-
>action, "upload errors check succeeded");
}
} }
} long long ierrors = Link_getErrorsInPerSecond(s->inf.net->stats)
long long ierrors = Link_getErrorsInPerSecond(s->inf.net->stats); ;
for (LinkStatus_T link = s->linkstatuslist; link; link = link->next) { for (LinkStatus_T link = s->linkstatuslist; link; link = link->n
if (ierrors > 0) { ext) {
rv = State_Failed; if (ierrors > 0) {
Event_post(s, Event_Link, State_Failed, link->action, "% rv = State_Failed;
lld download errors detected", ierrors); Event_post(s, Event_Link, State_Failed, link->ac
} else { tion, "%lld download errors detected", ierrors);
Event_post(s, Event_Link, State_Succeeded, link->action, } else {
"download errors check succeeded"); Event_post(s, Event_Link, State_Succeeded, link-
>action, "download errors check succeeded");
}
} }
} }
// Link speed // Link speed
int duplex = Link_getDuplex(s->inf.net->stats); int duplex = Link_getDuplex(s->inf.net->stats);
long long speed = Link_getSpeed(s->inf.net->stats); long long speed = Link_getSpeed(s->inf.net->stats);
for (LinkSpeed_T link = s->linkspeedlist; link; link = link->next) { for (LinkSpeed_T link = s->linkspeedlist; link; link = link->next) {
if (speed > 0 && link->speed) { if (speed > 0 && link->speed) {
if (duplex > -1 && duplex != link->duplex) if (duplex > -1 && duplex != link->duplex)
Event_post(s, Event_Speed, State_Changed, link-> action, "link mode is now %s-duplex", duplex ? "full" : "half"); Event_post(s, Event_Speed, State_Changed, link-> action, "link mode is now %s-duplex", duplex ? "full" : "half");
else else
 End of changes. 20 change blocks. 
56 lines changed or deleted 117 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)