Here's what the function function get_host_status_xml_output in /usr/local/nagiosxi/html/includes/utils-xmlstatus.inc.php has:
Code: Select all
function get_host_status_xml_output($request_args)
{
global $sqlquery;
global $db_tables;
$output = "";
$totals = grab_array_var($request_args, 'totals', false);
// generate query
$fieldmap = array(
"name" => "obj1.name1",
"host_name" => "obj1.name1",
"display_name" => $db_tables[DB_NDOUTILS]["hosts"] . ".display_name",
"address" => $db_tables[DB_NDOUTILS]["hosts"] . ".address",
"alias" => $db_tables[DB_NDOUTILS]["hosts"] . ".alias",
"instance_id" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".instance_id",
"hoststatus_id" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".hoststatus_id",
"host_id" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".host_object_id",
"status_update_time" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".status_update_time",
"current_state" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".current_state",
"state_type" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".state_type",
"last_check" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".last_check",
"last_state_change" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".last_state_change",
"modified_attributes" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".modified_host_attributes",
"has_been_checked" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".has_been_checked",
"active_checks_enabled" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".active_checks_enabled",
"passive_checks_enabled" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".passive_checks_enabled",
"notifications_enabled" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".notifications_enabled",
"event_handler_enabled" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".event_handler_enabled",
"is_flapping" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".is_flapping",
"flap_detection_enabled" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".flap_detection_enabled",
"scheduled_downtime_depth" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".scheduled_downtime_depth",
"problem_acknowledged" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".problem_has_been_acknowledged",
"check_command" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".check_command",
"current_check_attempt" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".current_check_attempt",
"max_check_attempts" => $db_tables[DB_NDOUTILS]["hoststatus"] . ".max_check_attempts",
);
$objectauthfields = array(
"host_id"
);
$instanceauthfields = array(
"instance_id"
);
//Full data or just totals?
$q = ($totals == 1) ? $sqlquery['GetHostStatusCount'] : $sqlquery['GetHostStatus'];
$args = array(
"sql" => $q,
"fieldmap" => $fieldmap,
"objectauthfields" => $objectauthfields,
"objectauthperms" => P_READ,
"instanceauthfields" => $instanceauthfields,
"useropts" => $request_args, // ADDED 12/22/09 FOR NEW NON-BACKEND CALLS
);
$sql = generate_sql_query(DB_NDOUTILS, $args);
if (!isset($request_args['brevity']))
$brevity = 0;
else
$brevity = $request_args['brevity'];
if (!($rs = exec_sql_query(DB_NDOUTILS, $sql, false))) {
//handle_backend_db_error(DB_NDOUTILS);
} else {
//output_backend_header();
$output .= "<hoststatuslist>\n";
if ($totals == 1) { //return SQL count()
foreach ($rs as $row)
$count = empty($row['total']) ? 0 : $row['total'];
$output .= " <recordcount>" . $count . "</recordcount>\n";
} else //count full data set
$output .= " <recordcount>" . $rs->RecordCount() . "</recordcount>\n";
if (!isset($request_args["totals"])) {
while (!$rs->EOF) {
$output .= " <hoststatus id='" . get_xml_db_field_val($rs, 'hoststatus_id') . "'>\n";
$output .= get_xml_db_field(2, $rs, 'instance_id');
$output .= get_xml_db_field(2, $rs, 'host_object_id', 'host_id');
$output .= get_xml_db_field(2, $rs, 'host_name', 'name');
$output .= get_xml_db_field(2, $rs, 'display_name');
$output .= get_xml_db_field(2, $rs, 'address', 'address');
$output .= get_xml_db_field(2, $rs, 'host_alias', 'alias');
$output .= get_xml_db_field(2, $rs, 'status_update_time');
$output .= get_xml_db_field(2, $rs, 'output', 'status_text');
$output .= get_xml_db_field(2, $rs, 'long_output', 'status_text_long');
$output .= get_xml_db_field(2, $rs, 'current_state');
if ($brevity < 1) {
$output .= get_xml_db_field(2, $rs, 'icon_image');
$output .= get_xml_db_field(2, $rs, 'icon_image_alt');
$output .= get_xml_db_field(2, $rs, 'perfdata', 'performance_data');
$output .= get_xml_db_field(2, $rs, 'should_be_scheduled');
$output .= get_xml_db_field(2, $rs, 'check_type');
$output .= get_xml_db_field(2, $rs, 'last_state_change');
$output .= get_xml_db_field(2, $rs, 'last_hard_state_change');
$output .= get_xml_db_field(2, $rs, 'last_hard_state');
$output .= get_xml_db_field(2, $rs, 'last_time_up');
$output .= get_xml_db_field(2, $rs, 'last_time_down');
$output .= get_xml_db_field(2, $rs, 'last_time_unreachable');
$output .= get_xml_db_field(2, $rs, 'last_notification');
$output .= get_xml_db_field(2, $rs, 'next_notification');
$output .= get_xml_db_field(2, $rs, 'no_more_notifications');
$output .= get_xml_db_field(2, $rs, 'acknowledgement_type');
$output .= get_xml_db_field(2, $rs, 'current_notification_number');
$output .= get_xml_db_field(2, $rs, 'event_handler_enabled');
$output .= get_xml_db_field(2, $rs, 'process_performance_data');
$output .= get_xml_db_field(2, $rs, 'obsess_over_host');
$output .= get_xml_db_field(2, $rs, 'modified_host_attributes');
$output .= get_xml_db_field(2, $rs, 'event_handler');
$output .= get_xml_db_field(2, $rs, 'check_command');
$output .= get_xml_db_field(2, $rs, 'normal_check_interval');
$output .= get_xml_db_field(2, $rs, 'retry_check_interval');
$output .= get_xml_db_field(2, $rs, 'check_timeperiod_object_id', 'check_timeperiod_id');
}
if ($brevity < 2) {
$output .= get_xml_db_field(2, $rs, 'has_been_checked');
$output .= get_xml_db_field(2, $rs, 'current_check_attempt');
$output .= get_xml_db_field(2, $rs, 'max_check_attempts');
$output .= get_xml_db_field(2, $rs, 'last_check');
$output .= get_xml_db_field(2, $rs, 'next_check');
$output .= get_xml_db_field(2, $rs, 'state_type');
$output .= get_xml_db_field(2, $rs, 'notifications_enabled');
$output .= get_xml_db_field(2, $rs, 'problem_has_been_acknowledged', 'problem_acknowledged');
$output .= get_xml_db_field(2, $rs, 'passive_checks_enabled');
$output .= get_xml_db_field(2, $rs, 'active_checks_enabled');
$output .= get_xml_db_field(2, $rs, 'flap_detection_enabled');
$output .= get_xml_db_field(2, $rs, 'is_flapping');
$output .= get_xml_db_field(2, $rs, 'percent_state_change');
$output .= get_xml_db_field(2, $rs, 'latency');
$output .= get_xml_db_field(2, $rs, 'execution_time');
$output .= get_xml_db_field(2, $rs, 'scheduled_downtime_depth');
}
$output .= " </hoststatus>\n";
$rs->MoveNext();
}
}
$output .= "</hoststatuslist>\n";
}
return $output;
}
My PHP is piss poor but it seems in utils-api.inc.php like the entirety of the GET request is dumped into the function call:
Somewhere in utils-xmlstatus.inc.php the GET request must be parsed, but looking under the get_host_status_xml_output function it seems like the request is fed right into the SQL query here:
Where is the code for generate_sql_query? Or is that a more generic PHP function?