Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added hostcomment and servicecomment #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions statusJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@

$hosts = $data['hosts'];
$services = $data['services'];
$hostcomment = $data['hostcomment'];
$servicecomment = $data['servicecomment'];
$program = "";
if (array_key_exists("program", $data)) {
$program = $data['program'];
}

outputJson($hosts, $services, $program);
outputJson($hosts, $services, $hostcomment, $servicecomment, $program);

function outputJson($hosts, $services, $program)
function outputJson($hosts, $services, $hostcomment, $servicecomment, $program)
{
// begin outputting XML
header("Content-type: application/json");
Expand All @@ -62,6 +64,41 @@ function outputJson($hosts, $services, $program)
unset($key, $val);
echo ' },' . "\n";
}
// Host comments
if ($hostcomment != "") {
echo ' "hostcomment": {' . "\n";
foreach ($hostcomment as $hostName => $hostcommentArray) {
echo ' "' . jsonString($hostName) . '": {' . "\n";
foreach ($hostcommentArray as $key => $val) {
echo ' "' . jsonString($key) . '": "' . jsonString($val) . '"' . (isLast($hostcommentArray, $key) ? '' : ',') . "\n";
}
unset($key, $val);
echo ' }' . (isLast($hostcomment, $hostName) ? '' : ',') . "\n";
}
unset($hostName, $hostcommentArray);
echo ' },' . "\n";
}

// Service comments
if ($servicecomment != "") {
echo ' "servicecomment": {' . "\n";
foreach ($servicecomment as $hostName => $servicecomments) {
echo ' "' . jsonString($hostName) . '": {' . "\n";
foreach ($servicecomments as $servicecommentDesc => $servicecommentArray) {
echo ' "' . jsonString($servicecommentDesc) . '": {' . "\n";
foreach ($servicecommentArray as $key => $val) {
echo ' "' . jsonString($key) . '": "' . jsonString($val) . '"' . (isLast($servicecommentArray, $key) ? '' : ',') . "\n";
}
unset($key, $val);
echo ' }' . (isLast($servicecomments, $servicecommentDesc) ? '' : ',') . "\n";
}
echo ' }' . (isLast($servicecomment, $hostName) ? '' : ',') . "\n";
unset($servicecommentDesc, $servicecommentArray);
}
unset($hostName, $servicecomments);
echo ' },' . "\n";
}


// hosts
echo ' "hosts": {' . "\n";
Expand Down Expand Up @@ -255,6 +292,8 @@ function getData3($statusFile)

$hostStatus = array();
$serviceStatus = array();
$hostCommentStatus = array();
$serviceCommentStatus = array();
$programStatus = array();

#variables for total hosts and services
Expand Down Expand Up @@ -295,7 +334,11 @@ function getData3($statusFile)
$serviceStatus[$sectionData['host_name']][$sectionData['service_description']] = $sectionData;
} elseif ($sectionType == "hoststatus") {
$hostStatus[$sectionData["host_name"]] = $sectionData;
} elseif ($sectionType == "programstatus") {
} elseif ($sectionType == "hostcomment") {
$hostCommentStatus[$sectionData["host_name"]] = $sectionData;
} elseif ($sectionType == "servicecomment") {
$serviceCommentStatus[$sectionData["host_name"]][$sectionData["service_description"]] = $sectionData;
} elseif ($sectionType == "programstatus") {
$programStatus = $sectionData;
}
$inSection = false;
Expand All @@ -307,7 +350,7 @@ function getData3($statusFile)
$lineVal = substr($line, strpos($line, "=") + 1);

// add to the array as appropriate
if ($sectionType == "servicestatus" || $sectionType == "hoststatus" || $sectionType == "programstatus") {
if ($sectionType == "servicestatus" || $sectionType == "hoststatus" || $sectionType == "hostcomment" || $sectionType == "servicecomment" || $sectionType == "programstatus") {
if ($debug) {
echo "LINE " . $lineNum . ": lineKey=" . $lineKey . "= lineVal=" . $lineVal . "=\n";
}
Expand All @@ -320,7 +363,7 @@ function getData3($statusFile)

fclose($fh);

$retArray = array("hosts" => $hostStatus, "services" => $serviceStatus, "program" => $programStatus);
$retArray = array("hosts" => $hostStatus, "services" => $serviceStatus, "hostcomment" => $hostCommentStatus, "servicecomment" => $serviceCommentStatus, "program" => $programStatus);
return $retArray;
}

Expand Down