@cryptotaxi247 / netdata-1 / commits / f1657dbec

Add ignore-status option to freeipmi_plugin

Patrick Seal committed Sep 7, 2018 at 18:51 UTC f1657dbec43f2882377d7d7843f8f6f607679248
1 file changed +57
src/freeipmi_plugin.c
+57
@@ -558,6 +558,41 @@ static void excluded_record_ids_parse(const char *s) {
558 }
559 }
560
561 +static int *excluded_status_record_ids = NULL;
562 +size_t excluded_status_record_ids_length = 0;
563 +
564 +static void excluded_status_record_ids_parse(const char *s) {
565 + if(!s) return;
566 +
567 + while(*s) {
568 + while(*s && !isdigit(*s)) s++;
569 +
570 + if(isdigit(*s)) {
571 + char *e;
572 + unsigned long n = strtoul(s, &e, 10);
573 + s = e;
574 +
575 + if(n != 0) {
576 + excluded_status_record_ids = realloc(excluded_status_record_ids, (excluded_status_record_ids_length + 1) * sizeof(int));
577 + if(!excluded_status_record_ids) {
578 + fprintf(stderr, "freeipmi.plugin: failed to allocate memory. Exiting.");
579 + exit(1);
580 + }
581 + excluded_status_record_ids[excluded_status_record_ids_length++] = (int)n;
582 + }
583 + }
584 + }
585 +
586 + if(debug) {
587 + fprintf(stderr, "freeipmi.plugin: excluded status record ids:");
588 + size_t i;
589 + for(i = 0; i < excluded_status_record_ids_length; i++) {
590 + fprintf(stderr, " %d", excluded_status_record_ids[i]);
591 + }
592 + fprintf(stderr, "\n");
593 + }
594 +}
595 +
596
597 static int excluded_record_ids_check(int record_id) {
598 size_t i;
@@ -570,6 +605,17 @@ static int excluded_record_ids_check(int record_id) {
605 return 0;
606 }
607
608 +static int excluded_status_record_ids_check(int record_id) {
609 + size_t i;
610 +
611 + for(i = 0; i < excluded_status_record_ids_length; i++) {
612 + if(excluded_status_record_ids[i] == record_id)
613 + return 1;
614 + }
615 +
616 + return 0;
617 +}
618 +
619 static void netdata_get_sensor(
620 int record_id
621 , int sensor_number
@@ -642,6 +688,10 @@ static void netdata_get_sensor(
688 break;
689 }
690
691 + // check if it is excluded
692 + if(excluded_status_record_ids_check(record_id))
693 + return;
694 +
695 switch(sensor_state) {
696 case IPMI_MONITORING_STATE_NOMINAL:
697 netdata_sensors_states_nominal++;
@@ -1537,6 +1587,9 @@ int main (int argc, char **argv) {
1587 " ignore N1,N2,N3,... sensor IDs to ignore\n"
1588 " default: none\n"
1589 "\n"
1590 + " ignore-status N1,N2,N3,... sensor IDs to ignore status (nominal/warning/critical)\n"
1591 + " default: none\n"
1592 + "\n"
1593 " -v\n"
1594 " -V\n"
1595 " version print version and exit\n"
@@ -1597,6 +1650,10 @@ int main (int argc, char **argv) {
1650 excluded_record_ids_parse(argv[++i]);
1651 continue;
1652 }
1653 + else if(i < argc && strcmp("ignore-status", argv[i]) == 0) {
1654 + excluded_status_record_ids_parse(argv[++i]);
1655 + continue;
1656 + }
1657
1658 error("freeipmi.plugin: ignoring parameter '%s'", argv[i]);
1659 }