forked from rodrigofns/zabbix-service-tree
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathajaxServiceTree.php
39 lines (35 loc) · 1.15 KB
/
ajaxServiceTree.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
session_start();
require('inc/Connection.class.php');
require('inc/ServiceTree.class.php');
require_once('__conf.php');
require_once('i18n/i18n.php');
i18n_set_map('en', $LANG, false);
if(isset($_REQUEST['root']))
{
// List of root service names.
$dbh = Connection::GetDatabase();
header('Content-Type: application/json');
echo json_encode(ServiceTree::GetRootList($dbh));
}
else if( (isset($_REQUEST['serviceId']) && $_REQUEST['serviceId'] != '') ||
(isset($_REQUEST['serviceName']) && $_REQUEST['serviceName'] != '') )
{
// Build and return the service tree.
// Service may be queried by its ID or name.
$dbh = Connection::GetDatabase();
$serviceId = (isset($_REQUEST['serviceId']) && $_REQUEST['serviceId'] != '') ?
$_REQUEST['serviceId'] : ServiceTree::GetIdByName($dbh, $_REQUEST['serviceName']);
// Output JSON data.
$statusCount = array(0, 0, 0, 0, 0, 0);
$root = ServiceTree::GetAllToHtml5($dbh, $serviceId, $statusCount);
header('Content-Type: application/json');
echo json_encode(array(
'tree' => $root,
'statusCount' => $statusCount
));
}
else
{
Connection::HttpError(400, I('Service tree: no parameters, nothing to query.'));
}