Permalink
Browse files

Wait for socket readiness

  • Loading branch information...
NEMS Linux
NEMS Linux committed Dec 17, 2018
1 parent 4629f65 commit 4897f16526976142f6a696cca22f5febe11421f8
Showing with 38 additions and 6 deletions.
  1. +18 −2 info.sh
  2. +3 −1 stats-livestatus-full.sh
  3. +17 −3 stats.sh
20 info.sh
@@ -242,13 +242,29 @@ elif [[ $COMMAND == "socket" ]]; then
fi
echo $socket

elif [[ $COMMAND == "socketstatus" ]]; then
socket=$(/usr/local/bin/nems-info socket)
if [[ -e $socket ]]; then
echo 1
else
echo 0
fi

elif [[ $COMMAND == "hosts" ]]; then
socket=$(/usr/local/bin/nems-info socket)
/usr/local/share/nems/nems-scripts/stats-livestatus.py $socket hosts
if [[ -e $socket ]]; then
/usr/local/share/nems/nems-scripts/stats-livestatus.py $socket hosts
else
echo 0
fi

elif [[ $COMMAND == "services" ]]; then
socket=$(/usr/local/bin/nems-info socket)
/usr/local/share/nems/nems-scripts/stats-livestatus.py $socket services
if [[ -e $socket ]]; then
/usr/local/share/nems/nems-scripts/stats-livestatus.py $socket services
else
echo 0
fi

elif [[ $COMMAND == "downtimes" ]]; then
/usr/local/share/nems/nems-scripts/info2.sh 6
@@ -25,6 +25,8 @@ $custom_filters = array(
'host_name ~ ',
);
if (file_exists($socket_path)) {
function _print_duration($start_time, $end_time)
{
$duration = $end_time - $start_time;
@@ -251,6 +253,6 @@ EOQ;
if (!isset($nems->unhandled)) {
$nems->unhandled = array();
}
} // detect socket exists
echo json_encode($nems);
?>
@@ -5,12 +5,26 @@
// # Please do not deactivate this unless you absolutely have to.
// # Again, it's completely anonymous, and nothing private is revealed.
if (!file_exists('/var/log/nems/hw_model')) {
// Just in case this is the first boot and running at startup, let's hang tight for 30 seconds to let the data generate
sleep(30);
$v=0;
while (!file_exists('/var/log/nems/hw_model')) {
// Just in case this is the first boot and running at startup, let's hang tight to let the data generate
sleep(10);
$v++;
if ($v == 6) die('Timed out waiting for hw_model');
}
$v=0;
$socket=shell_exec('/usr/local/bin/nems-info socket');
$socketstatus=shell_exec('/usr/local/bin/nems-info socketstatus');
while ($socketstatus != 1) {
// waiting for the Nagios livestatus socket to become ready
sleep(10);
$socketstatus=shell_exec('/usr/local/bin/nems-info socketstatus');
$v++;
if ($v == 6) die('Timed out waiting for livestatus socket to become ready (is Nagios running?)');
}
exit('working');
$output = date('r') . PHP_EOL;
$load = sys_getloadavg();
$output .= 'LA: ' . $load[0] . PHP_EOL;

0 comments on commit 4897f16

Please sign in to comment.