mirror of
https://github.com/monitoring-plugins/monitoring-plugins.git
synced 2026-06-11 01:30:00 -04:00
Ok summary (#2270)
* lib: implement functionality to set ok summary * check_load: implement setting ok summary * OK summary for ntp_peer, ntp_time and users * check_apt: implement ok summary * check_curl: implement ok summary * check_disk: implement ok summary * check_dbi: implement ok summary * check_ldap: auto formatting * check_ldap: implement ok summary * check_ssh: implement ok summary * check_tcp: implement ok summary * fixup! check_curl: implement ok summary * fixup! check_dbi: implement ok summary * fixup! check_ldap: implement ok summary * fixup! check_ssh: implement ok summary * fixup! check_tcp: implement ok summary * check_apt: remove illegal free * check_mrtg: fix link * check_mrtg: implement ok summary * check_mrtgtraf: fix link * check_mrtgtraf: implement ok summary * check_mysql: implement ok summary * check_mysql_query: implement ok summary * check_pgsql: implement ok summary * check_radius: implement ok summary * check_real: implement ok summary * check_smtp: implement ok summary * check_snmp: implement ok summary * check_swap: implement ok summary * check_ups: add OK summary --------- Co-authored-by: Lorenz Kästle <lorenz.kaestle@netways.de>
This commit is contained in:
parent
992a4555ac
commit
9bbc764838
24 changed files with 90 additions and 18 deletions
26
lib/output.c
26
lib/output.c
|
|
@ -105,6 +105,7 @@ static inline char *fmt_subcheck_perfdata(mp_subcheck check) {
|
|||
*/
|
||||
mp_check mp_check_init(void) {
|
||||
mp_check check = {
|
||||
.ok_summary = NULL,
|
||||
.evaluation_function = &mp_eval_check_default,
|
||||
.default_output_override = NULL,
|
||||
.default_output_override_content = NULL,
|
||||
|
|
@ -211,6 +212,14 @@ int mp_add_subcheck_to_subcheck(mp_subcheck check[static 1], mp_subcheck subchec
|
|||
*/
|
||||
void mp_set_summary(mp_check check[static 1], char *summary) { check->summary = strdup(summary); }
|
||||
|
||||
/*
|
||||
* set the summary for the OK state
|
||||
* this allows to set the content in the first line of the plugin
|
||||
* if the overall state is OK
|
||||
*/
|
||||
void mp_set_ok_summary(mp_check check[static 1], char *ok_summary) {
|
||||
check->ok_summary = strdup(ok_summary);
|
||||
}
|
||||
/*
|
||||
* Generate the summary string of a mp_check object based on its subchecks
|
||||
*/
|
||||
|
|
@ -255,21 +264,12 @@ char *get_subcheck_summary(mp_check check) {
|
|||
}
|
||||
|
||||
if (result == NULL) {
|
||||
if (ok_count > 0) {
|
||||
// Nothing in result yet, we must be in an OK state
|
||||
if (check.ok_summary != NULL) {
|
||||
asprintf(&result, "%s", check.ok_summary);
|
||||
} else if (ok_count > 0) {
|
||||
asprintf(&result, "ok=%d", ok_count);
|
||||
}
|
||||
|
||||
if (warning_count > 0) {
|
||||
asprintf(&result, "%swarning=%d", (result == NULL ? "" : ", "), warning_count);
|
||||
}
|
||||
|
||||
if (critical_count > 0) {
|
||||
asprintf(&result, "%scritical=%d", (result == NULL ? "" : ", "), critical_count);
|
||||
}
|
||||
|
||||
if (unknown_count > 0) {
|
||||
asprintf(&result, "%sunknown=%d", (result == NULL ? "" : ", "), unknown_count);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ mp_output_detail_level mp_get_level_of_detail(void);
|
|||
typedef struct mp_check mp_check;
|
||||
struct mp_check {
|
||||
char *summary; // Overall summary, if not set a summary will be automatically generated
|
||||
char *ok_summary; // (optional) Summary if the overall state is OK
|
||||
mp_subcheck_list *subchecks;
|
||||
|
||||
// the evaluation_functions computes the state of check
|
||||
|
|
@ -88,6 +89,7 @@ int mp_add_subcheck_to_subcheck(mp_subcheck check[static 1], mp_subcheck);
|
|||
void mp_add_perfdata_to_subcheck(mp_subcheck check[static 1], mp_perfdata);
|
||||
|
||||
void mp_set_summary(mp_check check[static 1], char *summary);
|
||||
void mp_set_ok_summary(mp_check check[static 1], char *ok_summary);
|
||||
|
||||
mp_state_enum mp_compute_check_state(mp_check);
|
||||
mp_state_enum mp_compute_subcheck_state(mp_subcheck);
|
||||
|
|
|
|||
|
|
@ -204,6 +204,15 @@ int main(int argc, char **argv) {
|
|||
mp_add_subcheck_to_check(&overall, sc_security_updates);
|
||||
mp_add_subcheck_to_check(&overall, sc_other_updates);
|
||||
|
||||
char *ok_summary = NULL;
|
||||
|
||||
if (packages_available == 0) {
|
||||
ok_summary = "No pending updates";
|
||||
} else {
|
||||
xasprintf(&ok_summary, "%zu pending updates", packages_available);
|
||||
}
|
||||
mp_set_ok_summary(&overall, ok_summary);
|
||||
|
||||
mp_exit(overall);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -161,6 +161,8 @@ int main(int argc, char **argv) {
|
|||
mp_check overall = mp_check_init();
|
||||
mp_subcheck sc_test = check_http(config, working_state, 0);
|
||||
|
||||
mp_set_ok_summary(&overall, "Connection test succeeded");
|
||||
|
||||
mp_add_subcheck_to_check(&overall, sc_test);
|
||||
|
||||
mp_exit(overall);
|
||||
|
|
|
|||
|
|
@ -220,6 +220,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
mp_check overall = mp_check_init();
|
||||
|
||||
mp_set_ok_summary(&overall, "DBI check was successful");
|
||||
|
||||
mp_subcheck sc_connection_time = mp_subcheck_init();
|
||||
sc_connection_time = mp_set_subcheck_default_state(sc_connection_time, STATE_OK);
|
||||
xasprintf(&sc_connection_time.output, "Connection time: %f", conn_time);
|
||||
|
|
|
|||
|
|
@ -162,6 +162,9 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
mp_check overall = mp_check_init();
|
||||
|
||||
mp_set_ok_summary(&overall, "Filesystem checks succeeded");
|
||||
|
||||
if (config.path_select_list.length == 0) {
|
||||
mp_subcheck none_sc = mp_subcheck_init();
|
||||
xasprintf(&none_sc.output, "No filesystems were found for the provided parameters");
|
||||
|
|
|
|||
|
|
@ -98,6 +98,8 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
mp_check overall = mp_check_init();
|
||||
|
||||
mp_set_ok_summary(&overall, "LDAP check succeeded");
|
||||
|
||||
LDAP *ldap_connection;
|
||||
/* initialize ldap */
|
||||
{
|
||||
|
|
@ -428,7 +430,7 @@ check_ldap_config_wrapper process_arguments(int argc, char **argv) {
|
|||
die(STATE_UNKNOWN, "failed to parse number of entries critical threshold");
|
||||
}
|
||||
result.config.entries_thresholds =
|
||||
mp_thresholds_set_crit(result.config.entries_thresholds, tmp.range);
|
||||
mp_thresholds_set_crit(result.config.entries_thresholds, tmp.range);
|
||||
} break;
|
||||
#ifdef HAVE_LDAP_SET_OPTION
|
||||
case '2':
|
||||
|
|
|
|||
|
|
@ -145,6 +145,12 @@ int main(int argc, char **argv) {
|
|||
mp_set_format(config.output_format);
|
||||
}
|
||||
|
||||
char *ok_summary = NULL;
|
||||
xasprintf(&ok_summary, "Load: 1m: %f - 5m: %f - 15m: %f", load_values[0], load_values[1],
|
||||
load_values[2]);
|
||||
mp_set_ok_summary(&overall, ok_summary);
|
||||
free(ok_summary);
|
||||
|
||||
bool is_using_scaled_load_values = false;
|
||||
long numcpus;
|
||||
if (config.take_into_account_cpus && ((numcpus = GET_NUMBER_OF_CPUS()) > 0)) {
|
||||
|
|
@ -156,6 +162,11 @@ int main(int argc, char **argv) {
|
|||
load_values[2] / numcpus,
|
||||
};
|
||||
|
||||
xasprintf(&ok_summary, "Scaled Load (%ld CPUs): 1m: %f - 5m: %f - 15m: %f", numcpus,
|
||||
load_values[0], load_values[1], load_values[2]);
|
||||
mp_set_ok_summary(&overall, ok_summary);
|
||||
free(ok_summary);
|
||||
|
||||
mp_subcheck scaled_load_sc = mp_subcheck_init();
|
||||
scaled_load_sc = mp_set_subcheck_default_state(scaled_load_sc, STATE_OK);
|
||||
scaled_load_sc.output = "Scaled Load (divided by number of CPUs)";
|
||||
|
|
@ -254,7 +265,7 @@ int main(int argc, char **argv) {
|
|||
|
||||
if (top_proc.errorcode == OK) {
|
||||
// +1 here since the string list contains the header line
|
||||
for (unsigned long i = 0; i < config.n_procs_to_show +1; i++) {
|
||||
for (unsigned long i = 0; i < config.n_procs_to_show + 1; i++) {
|
||||
xasprintf(&top_proc_sc.output, "%s\n%s", top_proc_sc.output,
|
||||
top_proc.top_processes[i]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
mp_check overall = mp_check_init();
|
||||
|
||||
mp_set_ok_summary(&overall, "Values in MRTG log are OK");
|
||||
|
||||
/* open the MRTG log file for reading */
|
||||
mp_subcheck sc_open_mrtg_log_file = mp_subcheck_init();
|
||||
FILE *mtrg_log_file = fopen(config.log_file, "r");
|
||||
|
|
@ -436,7 +438,7 @@ void print_help(void) {
|
|||
printf(" %s\n", _("you can always hack the code to make this plugin work for you..."));
|
||||
printf(" %s\n",
|
||||
_("- MRTG stands for the Multi Router Traffic Grapher. It can be downloaded from"));
|
||||
printf(" %s\n", "http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html");
|
||||
printf(" %s\n", "https://oss.oetiker.ch/mrtg/");
|
||||
|
||||
printf(UT_SUPPORT);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,9 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
mp_check overall = mp_check_init();
|
||||
|
||||
mp_set_ok_summary(&overall, "Transfer rates in MRTG are OK");
|
||||
|
||||
mp_subcheck sc_open_mrtg_log_file = mp_subcheck_init();
|
||||
|
||||
/* open the MRTG log file for reading */
|
||||
|
|
@ -440,7 +443,7 @@ void print_help(void) {
|
|||
printf("\n");
|
||||
printf("%s\n", _("Notes:"));
|
||||
printf(" %s\n", _("- MRTG stands for Multi Router Traffic Grapher. It can be downloaded from"));
|
||||
printf(" %s\n", " http://ee-staff.ethz.ch/~oetiker/webtools/mrtg/mrtg.html");
|
||||
printf(" %s\n", " https://oss.oetiker.ch/mrtg/");
|
||||
printf(" %s\n", _("- While MRTG can monitor things other than traffic rates, this"));
|
||||
printf(" %s\n", _(" plugin probably won't work with much else without modification."));
|
||||
printf(" %s\n", _("- The calculated i/o rates are a little off from what MRTG actually"));
|
||||
|
|
|
|||
|
|
@ -121,6 +121,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
mp_check overall = mp_check_init();
|
||||
|
||||
mp_set_ok_summary(&overall, "Mariadb/MySQL seems to be ok");
|
||||
|
||||
mp_subcheck sc_connection = mp_subcheck_init();
|
||||
/* establish a connection to the server and check for errors */
|
||||
if (!mysql_real_connect(&mysql, config.db_host, config.db_user, config.db_pass, config.db,
|
||||
|
|
|
|||
|
|
@ -92,6 +92,9 @@ int main(int argc, char **argv) {
|
|||
}
|
||||
|
||||
mp_check overall = mp_check_init();
|
||||
|
||||
mp_set_ok_summary(&overall, "MySQL query is OK");
|
||||
|
||||
mp_subcheck sc_connect = mp_subcheck_init();
|
||||
|
||||
/* establish a connection to the server and error checking */
|
||||
|
|
|
|||
|
|
@ -708,6 +708,8 @@ int main(int argc, char *argv[]) {
|
|||
const ntp_request_result ntp_res = ntp_request(config);
|
||||
mp_check overall = mp_check_init();
|
||||
|
||||
mp_set_ok_summary(&overall, "NTP Server seems to be OK");
|
||||
|
||||
mp_subcheck sc_offset = mp_subcheck_init();
|
||||
xasprintf(&sc_offset.output, "offset");
|
||||
if (ntp_res.offset_result == STATE_UNKNOWN) {
|
||||
|
|
|
|||
|
|
@ -696,6 +696,8 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
mp_check overall = mp_check_init();
|
||||
|
||||
mp_set_ok_summary(&overall, "NTP time synchronisation seems to be working");
|
||||
|
||||
mp_subcheck sc_offset = mp_subcheck_init();
|
||||
offset_request_wrapper offset_result =
|
||||
offset_request(config.server_address, config.port, config.time_offset);
|
||||
|
|
|
|||
|
|
@ -214,6 +214,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
mp_check overall = mp_check_init();
|
||||
|
||||
mp_set_ok_summary(&overall, "Postgres check is OK");
|
||||
|
||||
mp_subcheck sc_connection = mp_subcheck_init();
|
||||
|
||||
if (PQstatus(conn) == CONNECTION_BAD) {
|
||||
|
|
|
|||
|
|
@ -171,6 +171,9 @@ int main(int argc, char **argv) {
|
|||
#endif
|
||||
|
||||
mp_check overall = mp_check_init();
|
||||
|
||||
mp_set_ok_summary(&overall, "Radius check is OK");
|
||||
|
||||
mp_subcheck sc_read_config = mp_subcheck_init();
|
||||
|
||||
char *str = strdup("dictionary");
|
||||
|
|
|
|||
|
|
@ -83,6 +83,9 @@ int main(int argc, char **argv) {
|
|||
time(&start_time);
|
||||
|
||||
mp_check overall = mp_check_init();
|
||||
|
||||
mp_set_ok_summary(&overall, "REAL check is OK");
|
||||
|
||||
mp_subcheck sc_connect = mp_subcheck_init();
|
||||
|
||||
/* try to connect to the host at the given port number */
|
||||
|
|
|
|||
|
|
@ -187,6 +187,9 @@ int main(int argc, char **argv) {
|
|||
my_tcp_connect(config.server_address, config.server_port, &socket_descriptor);
|
||||
|
||||
mp_check overall = mp_check_init();
|
||||
|
||||
mp_set_ok_summary(&overall, "SMTP connection check is OK");
|
||||
|
||||
mp_subcheck sc_tcp_connect = mp_subcheck_init();
|
||||
char buffer[MAX_INPUT_BUFFER];
|
||||
bool ssl_established = false;
|
||||
|
|
|
|||
|
|
@ -295,6 +295,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
mp_check overall = mp_check_init();
|
||||
|
||||
mp_set_ok_summary(&overall, "SNMP query is OK");
|
||||
|
||||
if (response.errorcode == OK) {
|
||||
mp_subcheck sc_successfull_query = mp_subcheck_init();
|
||||
xasprintf(&sc_successfull_query.output, "SNMP query was successful");
|
||||
|
|
|
|||
|
|
@ -93,6 +93,8 @@ int main(int argc, char **argv) {
|
|||
mp_set_format(config.output_format);
|
||||
}
|
||||
|
||||
mp_set_ok_summary(&overall, "SSH check was successful");
|
||||
|
||||
/* initialize alarm signal handling */
|
||||
signal(SIGALRM, socket_timeout_alarm_handler);
|
||||
alarm(socket_timeout);
|
||||
|
|
|
|||
|
|
@ -100,6 +100,9 @@ int main(int argc, char **argv) {
|
|||
|
||||
double percent_used;
|
||||
mp_check overall = mp_check_init();
|
||||
|
||||
mp_set_ok_summary(&overall, "Swap check is OK");
|
||||
|
||||
if (config.output_format_is_set) {
|
||||
mp_set_format(config.output_format);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -249,6 +249,8 @@ int main(int argc, char **argv) {
|
|||
mp_set_format(config.output_format);
|
||||
}
|
||||
|
||||
mp_set_ok_summary(&overall, "Connection succeeded");
|
||||
|
||||
/* set up the timer */
|
||||
signal(SIGALRM, socket_timeout_alarm_handler);
|
||||
alarm(socket_timeout);
|
||||
|
|
|
|||
|
|
@ -91,6 +91,8 @@ int main(int argc, char **argv) {
|
|||
|
||||
mp_check overall = mp_check_init();
|
||||
|
||||
mp_set_ok_summary(&overall, "UPS check is OK");
|
||||
|
||||
mp_subcheck sc_retrieve_status = mp_subcheck_init();
|
||||
|
||||
/* get the ups status if possible */
|
||||
|
|
|
|||
|
|
@ -111,8 +111,13 @@ int main(int argc, char **argv) {
|
|||
mp_add_subcheck_to_check(&overall, sc_users);
|
||||
mp_exit(overall);
|
||||
}
|
||||
/* check the user count against warning and critical thresholds */
|
||||
|
||||
char *ok_summary = NULL;
|
||||
xasprintf(&ok_summary, "Users on the system: %d", user_wrapper.users);
|
||||
mp_set_ok_summary(&overall, ok_summary);
|
||||
free(ok_summary);
|
||||
|
||||
/* check the user count against warning and critical thresholds */
|
||||
mp_perfdata users_pd = {
|
||||
.label = "users",
|
||||
.value = mp_create_pd_value(user_wrapper.users),
|
||||
|
|
|
|||
Loading…
Reference in a new issue