@cryptotaxi247 / netdata-1 / commits / 63dab3fb4

added option to ignore sensor ids; fixes #3052

Costa Tsaousis (ktsaou) committed Nov 24, 2017 at 02:36 UTC 63dab3fb4d19f413a3a198c4b5f32c7d07e1ed45
1 file changed +56
src/freeipmi_plugin.c
+56
@@ -522,6 +522,49 @@ static void send_metrics_to_netdata() {
522
523 }
524
525 +static int *excluded_record_ids = NULL;
526 +size_t excluded_record_ids_length = 0;
527 +
528 +static void excluded_record_ids_parse(const char *s) {
529 + if(!s) return;
530 +
531 + while(*s) {
532 + while(*s && !isdigit(*s)) s++;
533 +
534 + if(isdigit(*s)) {
535 + char *e;
536 + unsigned long n = strtoul(s, &e, 10);
537 + s = e;
538 +
539 + if(n != 0) {
540 + excluded_record_ids = realloc(excluded_record_ids, (excluded_record_ids_length + 1) * sizeof(int));
541 + excluded_record_ids[excluded_record_ids_length++] = (int)n;
542 + }
543 + }
544 + }
545 +
546 + if(debug) {
547 + fprintf(stderr, "freeipmi.plugin: excluded record ids:");
548 + size_t i;
549 + for(i = 0; i < excluded_record_ids_length; i++) {
550 + fprintf(stderr, " %d", excluded_record_ids[i]);
551 + }
552 + fprintf(stderr, "\n");
553 + }
554 +}
555 +
556 +
557 +static int excluded_record_ids_check(int record_id) {
558 + size_t i;
559 +
560 + for(i = 0; i < excluded_record_ids_length; i++) {
561 + if(excluded_record_ids[i] == record_id)
562 + return 1;
563 + }
564 +
565 + return 0;
566 +}
567 +
568 static void netdata_get_sensor(
569 int record_id
570 , int sensor_number
@@ -546,6 +589,10 @@ static void netdata_get_sensor(
589 if(!sn) {
590 // not found, create it
591
592 + // check if it is excluded
593 + if(excluded_record_ids_check(record_id))
594 + return;
595 +
596 sn = calloc(1, sizeof(struct sensor));
597 if(!sn) {
598 fatal("cannot allocate %zu bytes of memory.", sizeof(struct sensor));
@@ -1482,6 +1529,9 @@ int main (int argc, char **argv) {
1529 " sensor-config-file FILE filename to read sensor configuration\n"
1530 " default: %s\n"
1531 "\n"
1532 + " ignore N1,N2,N3,... sensor IDs to ignore\n"
1533 + " default: none\n"
1534 + "\n"
1535 " -v\n"
1536 " -V\n"
1537 " version print version and exit\n"
@@ -1538,10 +1588,16 @@ int main (int argc, char **argv) {
1588 if(debug) fprintf(stderr, "freeipmi.plugin: sensor config file set to '%s'\n", sensor_config_file);
1589 continue;
1590 }
1591 + else if(i < argc && strcmp("ignore", argv[i]) == 0) {
1592 + excluded_record_ids_parse(argv[++i]);
1593 + continue;
1594 + }
1595
1596 error("freeipmi.plugin: ignoring parameter '%s'", argv[i]);
1597 }
1598
1599 + errno = 0;
1600 +
1601 if(freq > netdata_update_every)
1602 netdata_update_every = freq;
1603