Skip to content

Commit

Permalink
cleanup whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed May 20, 2021
1 parent 1af9f65 commit 6d8c483
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions scripts/process_perfdata.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ my %conf = (
XML_ENC => "UTF-8",
XML_UPDATE_DELAY => 0, # Write XML only if file is older then XML_UPDATE_DELAY seconds
RRD_DAEMON_OPTS => "",
GEARMAN_HOST => "localhost:4730", # How many gearman worker childs to start
PREFORK => 2, # How many gearman worker childs to start
GEARMAN_HOST => "localhost:4730", # How many gearman worker childs to start
PREFORK => 2, # How many gearman worker childs to start
REQUESTS_PER_CHILD => 20000, # Restart after a given count of requests
ENCRYPTION => 1, # Decrypt mod_gearman packets
KEY => 'should_be_changed',
Expand Down Expand Up @@ -117,7 +117,7 @@ if ( $conf{USE_RRDs} == 1 ) {
}

#
# Include Gearman modules if needed
# Include Gearman modules if needed
#
if ( defined($opt_gm) ) {
unless ( eval "use Gearman::Worker;1" ) {
Expand Down Expand Up @@ -163,7 +163,7 @@ if( ! defined($opt_gm) ){
if($conf{ENCRYPTION} == 1){
print_log( "Encryptions is enabled", 0 );
read_keyfile($conf{'KEY_FILE'});
# fill key up to 32 bytes
# fill key up to 32 bytes
$conf{'KEY'} = substr($conf{'KEY'},0,32) . chr(0) x ( 32 - length( $conf{'KEY'} ) );
$cypher = Crypt::Rijndael->new( $conf{'KEY'}, Crypt::Rijndael::MODE_ECB() );
}
Expand Down Expand Up @@ -491,7 +491,7 @@ sub data2rrd {
$DS = 1;
# PNP 0.4.x Template compatibility
$NAGIOS{RRDFILE} = "";

#
$rrd_storage_type = "MULTIPLE";
$rrdfile = $conf{RRDPATH} . "/" . $data[$i]{hostname} . "/" . $data[$i]{servicedesc} . "_" . $data[$i]{name} . ".rrd";
Expand Down Expand Up @@ -722,7 +722,7 @@ sub write_env_to_template {
}

#
# Recursive Template search
# Recursive Template search
#
sub adjust_template {
my $command = shift;
Expand All @@ -737,14 +737,14 @@ sub adjust_template {
COMMAND => $command,
TEMPLATE => $template,
DSTYPE => $dstype,
RRD_STORAGE_TYPE => $conf{'RRD_STORAGE_TYPE'},
RRD_STORAGE_TYPE => $conf{'RRD_STORAGE_TYPE'},
RRD_HEARTBEAT => $conf{'RRD_HEARTBEAT'},
USE_MIN_ON_CREATE => 0,
USE_MAX_ON_CREATE => 0,
);

read_custom_template ( );
#
#
if ( $CTPL{'TEMPLATE'} ne $initial_template ){
read_custom_template ( );
}
Expand All @@ -769,7 +769,7 @@ sub read_custom_template {
$dstype = $conf{'UOM2TYPE'}{$uom};
print_log( "DEBUG: DSTYPE adjusted to $dstype by UOM", 3 );
}else {
$dstype = 'GAUGE';
$dstype = 'GAUGE';
}

print_log( "DEBUG: RAW Command -> $command", 3 );
Expand Down Expand Up @@ -955,7 +955,7 @@ sub _parse {
"min" => $6,
"max" => $7
);

$p{label} =~ s/[&"']//g; # cleanup
$p{name} =~ s/["']//g; # cleanup
$p{name} =~ s/[\/\\]/_/g; # cleanup
Expand Down Expand Up @@ -1014,7 +1014,7 @@ sub cleanup {
}

#
# Urlencode
# Urlencode
#
sub urlencode {
my $string = shift;
Expand Down Expand Up @@ -1355,15 +1355,15 @@ sub init_stats {

#
# Store some internal runtime infos
#
#
sub store_internals {
if( ! -w $conf{'STATS_DIR'}){
print_log("*** ERROR: ".$conf{'STATS_DIR'}." is not writable or does not exist",0);
return;
}
my $statsfile = $conf{'STATS_DIR'}."/".(int $stats{timet} / 60);
open( STAT, ">> $statsfile" ) or die "Cant create statistic file ", $!;
printf(STAT "%d %f %d %d %d %d %d %d\n", $stats{timet},$stats{runtime},$stats{rows},$stats{update},$stats{create},$stats{error},$stats{invalid},$stats{skipped});
printf(STAT "%d %f %d %d %d %d %d %d\n", $stats{timet},$stats{runtime},$stats{rows},$stats{update},$stats{create},$stats{error},$stats{invalid},$stats{skipped});
close(STAT);
check_internals();
}
Expand All @@ -1377,15 +1377,15 @@ sub check_internals {
opendir(STATS, $conf{'STATS_DIR'});
while ( defined ( my $file = readdir STATS) ){
next if $file =~ /^\.\.?$/; # skip . and ..
next if $file =~ /-PID-/; # skip temporary files
next if $file =~ /-PID-/; # skip temporary files
next if $file == (int $stats{timet} / 60); # skip our current file
push @files, $file;
}
read_internals(@files);
}

#
# Read and aggregate files found by check_internals()
# Read and aggregate files found by check_internals()
#
sub read_internals {
my @files = @_;
Expand All @@ -1410,7 +1410,7 @@ sub read_internals {
@chunks = split();
$stats{timet} = $chunks[0];
$stats{runtime} += $chunks[1];
$stats{rows} += $chunks[2];
$stats{rows} += $chunks[2];
$stats{update} += $chunks[3];
$stats{create} += $chunks[4];
$stats{error} += $chunks[5];
Expand All @@ -1423,20 +1423,20 @@ sub read_internals {
}
}
#
#
#
#
sub process_internals {
my $last_rrd_dtorage_type = $conf{'RRD_STORAGE_TYPE'};
$conf{'RRD_STORAGE_TYPE'} = "MULTIPLE";
%NAGIOS = (
%NAGIOS = (
HOSTNAME => '.pnp-internal',
DISP_HOSTNAME => 'pnp-internal',
SERVICEDESC => 'runtime',
DISP_SERVICEDESC => 'runtime',
TIMET => $stats{timet},
DATATYPE => 'SERVICEPERFDATA',
CHECK_COMMAND => 'pnp-runtime',
PERFDATA => "runtime=".$stats{runtime}."s rows=".$stats{rows}." errors=".$stats{error}." invalid=".$stats{invalid}." skipped=".$stats{skipped} ." update=".$stats{update}. " create=".$stats{create}
PERFDATA => "runtime=".$stats{runtime}."s rows=".$stats{rows}." errors=".$stats{error}." invalid=".$stats{invalid}." skipped=".$stats{skipped} ." update=".$stats{update}. " create=".$stats{create}
);
parse_perfstring( $NAGIOS{PERFDATA} );
$conf{'RRD_STORAGE_TYPE'} = $last_rrd_dtorage_type;
Expand Down Expand Up @@ -1485,9 +1485,9 @@ sub new_child {
$sigset = POSIX::SigSet->new(SIGINT);
sigprocmask(SIG_BLOCK, $sigset)
or die "Can't block SIGINT for fork: $!\n";

die "fork: $!" unless defined ($pid = fork);

if ($pid) {
# Parent records the child's birth and returns.
sigprocmask(SIG_UNBLOCK, $sigset)
Expand All @@ -1498,18 +1498,18 @@ sub new_child {
} else {
# Child can *not* return from this subroutine.
$SIG{INT} = 'DEFAULT'; # make SIGINT kill us as it did before

# unblock signals
sigprocmask(SIG_UNBLOCK, $sigset)
or die "Can't unblock SIGINT for fork: $!\n";

my $worker = Gearman::Worker->new();
my @job_servers = split(/,/, $conf{'GEARMAN_HOST'}); # allow multiple gearman job servers
my @job_servers = split(/,/, $conf{'GEARMAN_HOST'}); # allow multiple gearman job servers
$worker->job_servers(@job_servers);
$worker->register_function("perfdata", 2, sub { return main(@_); });
my %opt = (
on_complete => sub { $req++; },
stop_if => sub { if ( $req > $conf{'REQUESTS_PER_CHILD'} ) { return 1;}; }
my %opt = (
on_complete => sub { $req++; },
stop_if => sub { if ( $req > $conf{'REQUESTS_PER_CHILD'} ) { return 1;}; }
);
print_log("connecting to gearmand '".$conf{'GEARMAN_HOST'}."'",0);
$worker->work( %opt );
Expand Down Expand Up @@ -1612,7 +1612,7 @@ sub print_help {
Default: @sysconfdir@/process_perfdata.cfg

Gearman Worker Options:
--gearman
--gearman
Start in Gearman worker mode
--daemon
Run as daemon
Expand All @@ -1631,4 +1631,3 @@ sub print_version {
print "Copyright (c) 2005-2010 Joerg Linge <pitchfork\@pnp4nagios.org>\n";
exit 0;
}

0 comments on commit 6d8c483

Please sign in to comment.