forked from rodrigofns/zabbix-service-tree
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathajaxService.php
94 lines (85 loc) · 2.85 KB
/
ajaxService.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
session_start();
require('inc/Connection.class.php');
require('inc/ServiceTree.class.php');
// Preliminar setup.
{
// Validate authenticated client.
if(!isset($_SESSION['user']))
Connection::HttpError(401, I('You are not logged in, or your session expired.'));
// Establish database connection.
$dbh = Connection::GetDatabase();
}
// Process requests.
if(isset($_POST['save']))
{
// --- Save service information. -------------------------------------------
$data = (object)$_POST['data'];
if($data->triggerid == '') $data->triggerid = null;
ServiceTree::CreateThresholdWeightIfNotExist($dbh, $data->id);
try {
$dbh->beginTransaction();
Connection::QueryDatabase($dbh, '
UPDATE service_threshold SET
threshold_normal = ?,
threshold_information = ?,
threshold_alert = ?,
threshold_average = ?,
threshold_major = ?,
threshold_critical = ?
WHERE idservice = ?
', $data->threshold_normal, $data->threshold_information, $data->threshold_alert,
$data->threshold_average, $data->threshold_major, $data->threshold_critical,
$data->id);
Connection::QueryDatabase($dbh, '
UPDATE service_weight SET
weight_normal = ?,
weight_information = ?,
weight_alert = ?,
weight_average = ?,
weight_major = ?,
weight_critical = ?
WHERE idservice = ?
', $data->weight_normal, $data->weight_information, $data->weight_alert,
$data->weight_average, $data->weight_major, $data->weight_critical,
$data->id);
Connection::QueryDatabase($dbh, '
UPDATE services SET
name = ?,
algorithm = ?,
triggerid = ?,
showsla = ?,
goodsla = ?
WHERE serviceid = ?
', $data->name, $data->algorithm, $data->triggerid,
$data->showsla, $data->goodsla, $data->id);
Connection::QueryDatabase($dbh, 'DELETE FROM service_icon WHERE idservice = ?', $data->id);
if($data->imageid !== null)
Connection::QueryDatabase($dbh, 'INSERT INTO service_icon (idservice,idicon) VALUES (?,?)', $data->id, $data->imageid);
$dbh->commit();
} catch(Exception $e) {
$dbh->rollback();
Connection::HttpError(500,
sprintf(I('Failed to update service with id=%s.<br/>%s'), $data->id, $e->getMessage()) );
}
header('Content-Type: application/json');
echo json_encode(array( 'status' => 'ok' )); // output status
}
else if(isset($_REQUEST['serviceId']))
{
// --- Query service information. ------------------------------------------
header('Content-Type: application/json');
echo json_encode( ServiceTree::GetInfo($dbh, $_REQUEST['serviceId']) );
}
else if(isset($_POST['images']))
{
// --- Query all available images from Zabbix. -----------------------------
header('Content-Type: application/json');
echo json_encode( ServiceTree::GetAllImages($dbh) );
}
else
{
// --- No request? ---------------------------------------------------------
Connection::HttpError(400,
I('No retrieve/save service request... what are you trying to do?'));
}