forked from Cacti/cacti
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boost_rrdupdate.php
88 lines (73 loc) · 3.16 KB
/
boost_rrdupdate.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
#!/usr/bin/php -q
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2017 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
/* do NOT run this script through a web browser */
if (!isset($_SERVER['argv'][0]) || isset($_SERVER['REQUEST_METHOD']) || isset($_SERVER['REMOTE_ADDR'])) {
die('<br>This script is only meant to run at the command line.');
}
/* We are not talking to the browser */
$no_http_headers = true;
/* include important functions */
include_once('./include/global.php');
include_once($config['base_path'] . '/lib/poller.php');
include_once($config['base_path'] . '/lib/boost.php');
/* get the boost polling cycle */
$max_run_duration = read_config_option('boost_rrd_update_max_runtime');
/* process calling arguments, first remove the script name */
$parms = $_SERVER['argv'];
array_shift($parms);
/* second, get the socket integer value */
$socket_int_value = $parms[0];
array_shift($parms);
/* last, recombine the arguments */
$command = implode(' ', $parms);
/* execute the command */
if ($config['cacti_server_os'] == 'win32') {
$handle = popen($command, 'rb');
} else {
$handle = popen($command, 'r');
}
/* get the results */
$result = fread($handle, 1024);
if (trim($result) == '') {
$result = 'OK';
} else {
if (substr_count($result, "\r")) {
$result = str_replace("\r", '', $result);
}
$result_array = explode("\n", $result);
if (sizeof($result_array)) {
$result = $result_array[sizeof($result_array)-2];
} else {
$result = 'ERROR: Detected unknown error';
}
}
/* add the value to the table */
db_execute_prepared('INSERT INTO poller_output_boost_processes
(sock_int_value, status)
VALUES (?, ?)', array($socket_int_value, $result));
/* close the connection */
pclose($handle);
/* return the rrdupdate results */
return $result;