From 3592214f2469fba772d7ab2819174df51be9b09c Mon Sep 17 00:00:00 2001 From: NEMS Linux Date: Tue, 10 Sep 2019 13:14:50 -0400 Subject: [PATCH] Add perfdata_cutoff --- fixes.sh | 6 ++++++ info.sh | 13 +++++++++++++ perfdata-purge | 29 +++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100755 perfdata-purge diff --git a/fixes.sh b/fixes.sh index 5c33fd4..e9a0585 100755 --- a/fixes.sh +++ b/fixes.sh @@ -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 diff --git a/info.sh b/info.sh index cad51b7..4f6c36d 100755 --- a/info.sh +++ b/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 diff --git a/perfdata-purge b/perfdata-purge new file mode 100755 index 0000000..e7e44b1 --- /dev/null +++ b/perfdata-purge @@ -0,0 +1,29 @@ +#!/usr/bin/env php + 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; +?>