Skip to content

Commit

Permalink
Add perfdata_cutoff
Browse files Browse the repository at this point in the history
  • Loading branch information
NEMS Linux committed Sep 10, 2019
1 parent 93cf762 commit 3592214
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions fixes.sh
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions info.sh
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions perfdata-purge
@@ -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.