Skip to content

Commit

Permalink
Merge pull request #174 from lazyfrosch/feature/ignore-pattern
Browse files Browse the repository at this point in the history
Add ignore patterns for host, service and perfdata label
  • Loading branch information
lingej authored Mar 20, 2021
2 parents 2a8e312 + 7185e73 commit 3f3c8ec
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
21 changes: 21 additions & 0 deletions sample-config/pnp/process_perfdata.cfg-sample.in
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@ RRD_DAEMON_OPTS =
#
STATS_DIR = @localstatedir@/stats

#
# Ignore certain performance data based on host name
#
# You can put it any regular expression that matches the host name
#
#IGNORE_HOST_PATTERN =

#
# Ignore certain performance data based on service name
#
# You can put it any regular expression that matches the service name
#
#IGNORE_SERVICE_PATTERN =

#
# Ignore certain performance data based on label of an individual data point
#
# You can put it any regular expression that matches the label
#
#IGNORE_LABEL_PATTERN =


#########################################################
# Gearman Worker Config
Expand Down
26 changes: 26 additions & 0 deletions scripts/process_perfdata.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ my %conf = (
KEY => 'should_be_changed',
KEY_FILE => '@sysconfdir@/secret.key',
UOM2TYPE => { 'c' => 'DERIVE', 'd' => 'DERIVE' },
IGNORE_HOST_PATTERN => '',
IGNORE_SERVICE_PATTERN => '',
IGNORE_LABEL_PATTERN => '',
);

my %const = (
Expand Down Expand Up @@ -296,6 +299,7 @@ sub process_perfdata {
$stats{skipped}++;
return 1;
}

if ( ! defined($NAGIOS{PERFDATA}) && ! defined($opt_gm) ) {
print_log( "No Performance Data for $NAGIOS{HOSTNAME} / $NAGIOS{SERVICEDESC} ", 1 );
if ( !$opt_b && !$opt_s ) {
Expand All @@ -304,6 +308,20 @@ sub process_perfdata {
}
}

# Check if we want to ignore the host
my $pattern = $conf{IGNORE_HOST_PATTERN};
if ( $pattern ne '' && $NAGIOS{HOSTNAME} =~ /$pattern/) {
print_log( "Ignoring host due to a pattern: $NAGIOS{HOSTNAME}", 1 );
next;
}

# Check if we want to ignore the service
$pattern = $conf{IGNORE_SERVICE_PATTERN};
if ( $pattern ne '' && $NAGIOS{SERVICEDESC} =~ /$pattern/) {
print_log( "Ignoring service due to a pattern: $NAGIOS{SERVICEDESC}", 1 );
next;
}

if ( $NAGIOS{PERFDATA} =~ /^(.*)\s\[(.*)\]$/ ) {
$NAGIOS{PERFDATA} = $1;
$NAGIOS{CHECK_COMMAND} = $2;
Expand Down Expand Up @@ -1173,6 +1191,14 @@ sub parse_perfstring {
@perfs = ();
last;
}

# Check if we want to ignore the perfdata by label
my $ignore_pattern = $conf{IGNORE_LABEL_PATTERN};
if ( $ignore_pattern ne '' && $p{label} =~ /$ignore_pattern/) {
print_log( "Ignoring perfdata label due to a pattern: $p{label}", 1 );
next;
}

%CTPL = adjust_template( $NAGIOS{CHECK_COMMAND}, $p{uom}, $count );

if ( $CTPL{'USE_MAX_ON_CREATE'} == 1 && defined $p{max} ) {
Expand Down

0 comments on commit 3f3c8ec

Please sign in to comment.