Skip to content
Permalink
Browse files

Add perfdata_cutoff

  • Loading branch information...
NEMS Linux
NEMS Linux committed Sep 10, 2019
1 parent 93cf762 commit 3592214f2469fba772d7ab2819174df51be9b09c
Showing with 48 additions and 0 deletions.
  1. +6 −0 fixes.sh
  2. +13 −0 info.sh
  3. +29 −0 perfdata-purge
@@ -46,6 +46,12 @@
fi
fi

# Clear old perfdata from the log
purgeDate=$(date -d '90 days ago' +%s)
if [[ $purgeDate > 0 ]]; then
awk -v m=$purgeDate '{k=$1 OFS $2} $2<=m {next} {print}' /usr/local/nagios/var/perfdata.log > /tmp/test.log
fi

# Update apt here so we don't have to do it below
apt clean
apt update --allow-releaseinfo-change
13 info.sh
@@ -80,6 +80,19 @@ elif [[ $COMMAND == "checkport" ]]; then
elif [[ $COMMAND == "nemsver" ]]; then
cat /usr/local/share/nems/nems.conf | grep version | printf '%s' $(cut -n -d '=' -f 2)

# perfdata cutoff time (in days)
elif [[ $COMMAND == "perfdata_cutoff" ]]; then
perfdata_cutoff=`cat /usr/local/share/nems/nems.conf | grep perfdata_cutoff | printf '%s' $(cut -n -d '=' -f 2)`
if [[ $perfdata_cutoff != "" ]]; then
if (( $perfdata_cutoff >= 0 )); then
echo $perfdata_cutoff
else
echo 0
fi
else
echo 0
fi

elif [[ $COMMAND == "tv_require_notify" ]]; then
tv_require_notify=`cat /usr/local/share/nems/nems.conf | grep tv_require_notify | printf '%s' $(cut -n -d '=' -f 2)`
if [[ $tv_require_notify == 2 ]]; then
@@ -0,0 +1,29 @@
#!/usr/bin/env php
<?php
$cutoff = intval(shell_exec('/usr/local/bin/nems-info perfdata_cutoff'));
if ($cutoff > 0) {
$file = '/usr/local/nagios/var/perfdata.log';
$perfdata = file($file);
$datachanged = 0;
if (is_array($perfdata)) {
foreach ($perfdata as $key => $line) {
$tmp = explode('||',$line);
$timestamp = $tmp[0];
if ($timestamp < strtotime($cutoff . ' days ago')) {
unset($perfdata[$key]);
$datachanged = 1;
}
}
if ($datachanged == 1) {
$output = '';
foreach ($perfdata as $line) {
$output .= $line;
}
file_put_contents($file,$output);
}
}
} else {
echo 'perfdata will not be purged since no cutoff is specified in NEMS SST.';
}
echo PHP_EOL;
?>

0 comments on commit 3592214

Please sign in to comment.
You can’t perform that action at this time.