diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2018-11-07 12:22:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2018-11-07 12:22:44 +0000 |
commit | 1e6c93250172946eeb38e94a92a1fd12c9d3011e (patch) | |
tree | 8ca5e16dfc7ad6b3bf2738ca0a48408a950f8f7e /collectors/freeipmi.plugin/freeipmi_plugin.c | |
parent | Update watch file (diff) | |
download | netdata-1e6c93250172946eeb38e94a92a1fd12c9d3011e.tar.xz netdata-1e6c93250172946eeb38e94a92a1fd12c9d3011e.zip |
Merging upstream version 1.11.0+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | collectors/freeipmi.plugin/freeipmi_plugin.c (renamed from src/freeipmi_plugin.c) | 104 |
1 files changed, 92 insertions, 12 deletions
diff --git a/src/freeipmi_plugin.c b/collectors/freeipmi.plugin/freeipmi_plugin.c index df4c019a4..a1cff3af0 100644 --- a/src/freeipmi_plugin.c +++ b/collectors/freeipmi.plugin/freeipmi_plugin.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-3.0-or-later /* * netdata freeipmi.plugin * Copyright (C) 2017 Costa Tsaousis @@ -14,7 +15,7 @@ * UCRL-CODE-222073 */ -#include "common.h" +#include "../../libnetdata/libnetdata.h" #include <stdio.h> #include <stdlib.h> @@ -27,6 +28,32 @@ #ifdef HAVE_FREEIPMI +// ---------------------------------------------------------------------------- + +// callback required by fatal() +void netdata_cleanup_and_exit(int ret) { + exit(ret); +} + +// callbacks required by popen() +void signals_block(void) {}; +void signals_unblock(void) {}; +void signals_reset(void) {}; + +// callback required by eval() +int health_variable_lookup(const char *variable, uint32_t hash, struct rrdcalc *rc, calculated_number *result) { + (void)variable; + (void)hash; + (void)rc; + (void)result; + return 0; +}; + +// required by get_system_cpus() +char *netdata_configured_host_prefix = ""; + +// ---------------------------------------------------------------------------- + #include <ipmi_monitoring.h> #include <ipmi_monitoring_bitmasks.h> @@ -46,8 +73,8 @@ char *driver_device = NULL; /* not used if probing */ int protocol_version = -1; //IPMI_MONITORING_PROTOCOL_VERSION_1_5; /* or -1 for default */ char *username = "foousername"; char *password = "foopassword"; -unsigned char *k_g = NULL; -unsigned int k_g_len = 0; +unsigned char *ipmi_k_g = NULL; +unsigned int ipmi_k_g_len = 0; int privilege_level = -1; // IPMI_MONITORING_PRIVILEGE_LEVEL_USER; /* or -1 for default */ int authentication_type = -1; // IPMI_MONITORING_AUTHENTICATION_TYPE_MD5; /* or -1 for default */ int cipher_suite_id = 0; /* or -1 for default */ @@ -123,8 +150,8 @@ _init_ipmi_config (struct ipmi_monitoring_ipmi_config *ipmi_config) ipmi_config->protocol_version = protocol_version; ipmi_config->username = username; ipmi_config->password = password; - ipmi_config->k_g = k_g; - ipmi_config->k_g_len = k_g_len; + ipmi_config->k_g = ipmi_k_g; + ipmi_config->k_g_len = ipmi_k_g_len; ipmi_config->privilege_level = privilege_level; ipmi_config->authentication_type = authentication_type; ipmi_config->cipher_suite_id = cipher_suite_id; @@ -557,6 +584,41 @@ static void excluded_record_ids_parse(const char *s) { } } +static int *excluded_status_record_ids = NULL; +size_t excluded_status_record_ids_length = 0; + +static void excluded_status_record_ids_parse(const char *s) { + if(!s) return; + + while(*s) { + while(*s && !isdigit(*s)) s++; + + if(isdigit(*s)) { + char *e; + unsigned long n = strtoul(s, &e, 10); + s = e; + + if(n != 0) { + excluded_status_record_ids = realloc(excluded_status_record_ids, (excluded_status_record_ids_length + 1) * sizeof(int)); + if(!excluded_status_record_ids) { + fprintf(stderr, "freeipmi.plugin: failed to allocate memory. Exiting."); + exit(1); + } + excluded_status_record_ids[excluded_status_record_ids_length++] = (int)n; + } + } + } + + if(debug) { + fprintf(stderr, "freeipmi.plugin: excluded status record ids:"); + size_t i; + for(i = 0; i < excluded_status_record_ids_length; i++) { + fprintf(stderr, " %d", excluded_status_record_ids[i]); + } + fprintf(stderr, "\n"); + } +} + static int excluded_record_ids_check(int record_id) { size_t i; @@ -569,6 +631,17 @@ static int excluded_record_ids_check(int record_id) { return 0; } +static int excluded_status_record_ids_check(int record_id) { + size_t i; + + for(i = 0; i < excluded_status_record_ids_length; i++) { + if(excluded_status_record_ids[i] == record_id) + return 1; + } + + return 0; +} + static void netdata_get_sensor( int record_id , int sensor_number @@ -641,6 +714,10 @@ static void netdata_get_sensor( break; } + // check if it is excluded + if(excluded_status_record_ids_check(record_id)) + return; + switch(sensor_state) { case IPMI_MONITORING_STATE_NOMINAL: netdata_sensors_states_nominal++; @@ -672,10 +749,6 @@ static void netdata_get_sel( } -void netdata_cleanup_and_exit(int ret) { - exit(ret); -} - // END NETDATA CODE // ---------------------------------------------------------------------------- @@ -1478,8 +1551,8 @@ int main (int argc, char **argv) { int i, freq = 0; for(i = 1; i < argc ; i++) { if(isdigit(*argv[i]) && !freq) { - int n = atoi(argv[i]); - if(n > 0 && freq < 86400) { + int n = str2i(argv[i]); + if(n > 0 && n < 86400) { freq = n; continue; } @@ -1536,6 +1609,9 @@ int main (int argc, char **argv) { " ignore N1,N2,N3,... sensor IDs to ignore\n" " default: none\n" "\n" + " ignore-status N1,N2,N3,... sensor IDs to ignore status (nominal/warning/critical)\n" + " default: none\n" + "\n" " -v\n" " -V\n" " version print version and exit\n" @@ -1548,7 +1624,7 @@ int main (int argc, char **argv) { " options ipmi_si kipmid_max_busy_us=10\n" "\n" " For more information:\n" - " https://github.com/firehol/netdata/wiki/monitoring-IPMI\n" + " https://github.com/ktsaou/netdata/tree/master/plugins/freeipmi.plugin\n" "\n" , VERSION , netdata_update_every @@ -1596,6 +1672,10 @@ int main (int argc, char **argv) { excluded_record_ids_parse(argv[++i]); continue; } + else if(i < argc && strcmp("ignore-status", argv[i]) == 0) { + excluded_status_record_ids_parse(argv[++i]); + continue; + } error("freeipmi.plugin: ignoring parameter '%s'", argv[i]); } |