forked from librenms/librenms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-services.php
executable file
·70 lines (60 loc) · 1.87 KB
/
check-services.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
#!/usr/bin/env php
<?php
/*
* LibreNMS module to poll Nagios Services
*
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
*
* 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 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
$init_modules = array();
require __DIR__ . '/includes/init.php';
$options = getopt('d::h:f:;');
if (isset($options['d'])) {
echo "DEBUG!\n";
$debug = true;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('log_errors', 1);
ini_set('error_reporting', 1);
} else {
$debug = false;
// ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
ini_set('log_errors', 0);
// ini_set('error_reporting', 0);
}
if (isset($options['f'])) {
$config['noinfluxdb'] = true;
}
if (isset($options['p'])) {
$prometheus = false;
}
if ($config['noinfluxdb'] !== true && $config['influxdb']['enable'] === true) {
$influxdb = influxdb_connect();
} else {
$influxdb = false;
}
rrdtool_initialize();
$where = '';
if ($options['h']) {
if (is_numeric($options['h'])) {
$where = "AND `S`.`device_id` = ".$options['h'];
} else {
if (preg_match('/\*/', $options['h'])) {
$where = "AND `hostname` LIKE '".str_replace('*', '%', mres($options['h']))."'";
} else {
$where = "AND `hostname` = '".mres($options['h'])."'";
}
}
}
$sql = 'SELECT * FROM `devices` AS D, `services` AS S WHERE S.device_id = D.device_id ' . $where . ' ORDER by D.device_id DESC';
foreach (dbFetchRows($sql) as $service) {
// Run the polling function
poll_service($service);
} //end foreach
rrdtool_close();