Permalink
Browse files

Upgrade Nagios. Don't checkin if offline.

  • Loading branch information...
NEMS Linux
NEMS Linux committed Feb 6, 2019
1 parent 27d91f5 commit aae0fd58ef8170b99cfb231718cd5fca210de85a
Showing with 9 additions and 2 deletions.
  1. +9 −2 checkin.sh
@@ -62,7 +62,10 @@ $output = date('r') . PHP_EOL;
$output .= 'Checking in: ';
file_put_contents('/var/log/nems/checkin.log',$output,FILE_APPEND);
# Setup the data array
# only proceed if Nagios is running
$socket = trim(shell_exec('/usr/local/bin/nems-info socket'));
if (file_exists($socket)) {
# Setup the data array
$data = array(
'hwid'=>trim(shell_exec('/usr/local/bin/nems-info hwid')),
@@ -82,7 +85,7 @@ file_put_contents('/var/log/nems/checkin.log',$output,FILE_APPEND);
}
}
# Connect and checkin
# Connect and checkin
$ch = curl_init('https://nemslinux.com/api/checkin/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
@@ -107,6 +110,10 @@ file_put_contents('/var/log/nems/checkin.log',$output,FILE_APPEND);
file_put_contents('/usr/local/share/nems/nems.conf','apikey=' . $newkey . PHP_EOL, FILE_APPEND);
file_put_contents('/var/log/nems/checkin.log','Assigned new API Key by server: ' . $newkey . PHP_EOL,FILE_APPEND);
}
} else {
echo 'Nagios is offline. Will not checkin.' . PHP_EOL;
file_put_contents('/var/log/nems/checkin.log','Nagios is offline. Will not checkin.' . PHP_EOL,FILE_APPEND);
}
file_put_contents('/var/log/nems/checkin.log','--------------------' . PHP_EOL,FILE_APPEND);

0 comments on commit aae0fd5

Please sign in to comment.