Skip to content

Commit 6c28fdd

Browse files
xmacanTheWitness
andauthored
Preparing v 0.4 (#81)
* remove hardcoded timeout * update * better themes support, css separated files * csfixer * add info about template * add phpdoc * csfixer --------- Co-authored-by: TheWitness <thewitness@cacti.net>
1 parent 0451429 commit 6c28fdd

26 files changed

Lines changed: 1358 additions & 451 deletions

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
* feature: Add cpu/memory statistics
88
* feature: Better process control
99
* feature: Add return data size stats
10-
* feature: Add log renention
10+
* feature: Add log retention
1111
* feature: Command run only for selected tests
12+
* feature: Add configurable test timeout
13+
* feature: Add Servcheck graph template
14+
* issue: Better themes support
1215

1316
--- 0.3 ---
1417

README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
This is Cacti's Services monitoring plugin. Based on Webseer plugin.
66
This plugin allows you to add service monitoring to Cacti.
7-
You simply add service check, allow service specific test
7+
You simply add service check, allow service specific test
88
(like certificate check, long duration check, ...)
9-
and you can add the expected response. Servcheck periodically run test
9+
and you can add the expected response. Servcheck periodically run test
1010
and notify if a service check fails. The plugin records statistics
11-
about the connection and service response. Servcheck can send email notification
11+
about the connection and service response. Servcheck can send email notification
1212
or run script when the status changes.
1313

1414
This plugin, like many others, integrates with Cacti's Maintenance or 'maint'
@@ -18,10 +18,10 @@ take place during maintenance periods.
1818

1919

2020
## Tests and results
21-
Setvcheck try to run test once or more than once (you can configure it).
22-
If successful on the first attempt, no further
23-
tests will be performed. Main result is ok/error. A lot of information
24-
are returned with main result. After the test is completed, statistics are generated.
21+
Setvcheck try to run test once or more than once (you can configure it).
22+
If successful on the first attempt, no further tests will be performed.
23+
Main result is ok/error. A lot of information are returned with main result.
24+
After the test is completed, statistics are generated.
2525
Based on the statistics, email notifications can be sent:
2626
- service state change
2727
- search text in result change
@@ -45,18 +45,24 @@ MQTT - try to subscribe topic or wait for any message and print result
4545
SNMP - get or walk specified OID and return answer
4646
SSH_COMMAND - ssh connect, run command and return output
4747

48+
## Graph template
49+
You can create graph for each test. How to and template is in templates directory.
4850

4951
## Important
5052
Servcheck has great debug output. If you have any problem, try to run your test:
5153
/path/to/php servcheck_process.php --id=<ID> --force --debug
5254

5355
Example_script.sh shows you how to use returned variables in own script.
5456

57+
Test duration - default test duration is 5 seconds, you can change it in settings. If you need different for
58+
specific test, change "Long duration alert" parametr in test. After that the max. duration will be
59+
Long duration alert + 2 seconds.
60+
5561
Recommendation for tests with download - please download only small not binary files.
5662

5763
Default Libcurl build doesn't compile all services. You have to compile again for SMB, LDAP, ...
5864

59-
For POP3 and IMAP tests is better insert correct username and password. Without credentials,
65+
For POP3 and IMAP tests is better insert correct username and password. Without credentials,
6066
curl can will return incorrect result.
6167

6268
SCP is in insecure mode - doesn't check SSH server key!

includes/arrays.php

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,12 @@
4242
];
4343

4444
$servcheck_states = [
45-
'error' => [
46-
'color' => '#FB4A14',
47-
'display' => __('Error', 'servcheck')
48-
],
49-
'duration' => [
50-
'color' => '#CDFDFF',
51-
'display' => __('Long duration', 'servcheck')
52-
],
53-
'warning' => [
54-
'color' => '#FCAA94',
55-
'display' => __('Warning', 'servcheck')
56-
],
57-
'failing' => [
58-
'color' => '#FAFD9E',
59-
'display' => __('Failing', 'servcheck')
60-
],
61-
'ok' => [
62-
'color' => '#E0FFE0',
63-
'display' => __('Ok', 'servcheck')
64-
],
65-
'disabled' => [
66-
'color' => '#CDCFC4',
67-
'display' => __('Disabled', 'servcheck')
68-
]
45+
'error' => __('Error', 'servcheck'),
46+
'duration' => __('Long duration', 'servcheck'),
47+
'warning' => __('Warning', 'servcheck'),
48+
'failing' => __('Failing', 'servcheck'),
49+
'ok' => __('Ok', 'servcheck'),
50+
'disabled' => __('Disabled', 'servcheck')
6951
];
7052

7153
$service_types = [
@@ -555,7 +537,7 @@
555537
'default' => 0,
556538
'max_length' => '5',
557539
'size' => '30',
558-
'description' => __('If the test time is greater than this value more times in a row, send a notification. Related to variable Duration count.', 'servcheck'),
540+
'description' => __('If the test time is greater than this value more times in a row, send a notification. Related to variable Duration count. The test inherits the maximum runtime from the settings. If a higher value is set here, the maximum runtime is this value + 2 seconds.', 'servcheck'),
559541
'value' => '|arg1:duration_trigger|',
560542
],
561543
'duration_count' => [
@@ -936,7 +918,7 @@
936918
'ftp_scp' => __('Encrypted SCP connection, login and try to download file specified in path (/path/to/file.txt).', 'servcheck'),
937919
'smb_smb' => __('Try SMB protocol, username and password are required. Try to login and download file.', 'servcheck'),
938920
'smb_smbs' => __('Try SMB protocol, username and password are required. Try to login and download file.', 'servcheck'),
939-
'mqtt_mqtt' => __('Connetct to MQTT server and listen for any message. You can specify topic in Path (bedroom/temp), blank for any topic', 'servcheck'),
921+
'mqtt_mqtt' => __('Connetct to MQTT server and listen for any message. You can specify topic in Path (bedroom/temp), blank for any topic. For this test is recommended increase \"Long duration alert\"', 'servcheck'),
940922
'rest_basic' => __('REST API test with basic HTTP auth. Prepare credential first.', 'servcheck'),
941923
'rest_apikey' => __('REST API test with API key auth. Prepare credential first.', 'servcheck'),
942924
'rest_oauth2' => __('REST API test with Oauth2. Prepare credential first.', 'servcheck'),

includes/functions.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ function servcheck_check_debug() {
6363
}
6464
}
6565

66+
/**
67+
* Log debug message
68+
*
69+
* @param string $message Text of the message that will be logged
70+
*
71+
* @return void
72+
*/
6673
function servcheck_debug($message = '') {
6774
global $debug;
6875

@@ -226,7 +233,7 @@ function servcheck_legend() {
226233
print '<tr class="tableRow">';
227234

228235
foreach ($servcheck_states as $index => $state) {
229-
print '<td style="background-color: ' . $state['color'] . '">' . $state['display'] . '</td>';
236+
print '<td class="servcheck_' . $index . '">' . $state . '</td>';
230237
}
231238
print '</tr>';
232239

includes/test_curl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function curl_try($test) {
4444
CURLOPT_RETURNTRANSFER => true,
4545
CURLOPT_FOLLOWLOCATION => true,
4646
CURLOPT_MAXREDIRS => 4,
47-
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 1) : 5,
47+
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
4848
CURLOPT_CAINFO => $ca_info,
4949
];
5050

includes/test_dns.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function dns_try($test) {
3838

3939
servcheck_debug('Querying ' . $test['hostname'] . ' for record ' . $test['dns_query']);
4040

41-
$a = new mxlookup($test['dns_query'], $test['hostname'], $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 3) : 5);
41+
$a = new mxlookup($test['dns_query'], $test['hostname'], $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'));
4242

4343
if (!cacti_sizeof($a->arrMX)) {
4444
$results['result'] = 'error';
@@ -117,7 +117,7 @@ function doh_try($test) {
117117
CURLOPT_RETURNTRANSFER => true,
118118
CURLOPT_FOLLOWLOCATION => true,
119119
CURLOPT_MAXREDIRS => 4,
120-
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 3) : 5,
120+
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
121121
CURLOPT_CAINFO => $ca_info,
122122
];
123123

includes/test_ftp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function ftp_try($test) {
4343
CURLOPT_RETURNTRANSFER => true,
4444
CURLOPT_FOLLOWLOCATION => true,
4545
CURLOPT_MAXREDIRS => 4,
46-
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 1) : 5,
46+
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
4747
CURLOPT_CAINFO => $ca_info,
4848
];
4949

includes/test_mail.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function mail_try($test) {
123123
'tcp://' . $test['hostname'],
124124
$errno,
125125
$errstr,
126-
3,
126+
$test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
127127
STREAM_CLIENT_CONNECT,
128128
$context
129129
);
@@ -153,7 +153,7 @@ function mail_try($test) {
153153
'ssl://' . $test['hostname'],
154154
$errno,
155155
$errstr,
156-
3,
156+
$test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
157157
STREAM_CLIENT_CONNECT,
158158
$context
159159
);
@@ -204,7 +204,7 @@ function mail_try($test) {
204204
'tcp://' . $test['hostname'],
205205
$errno,
206206
$errstr,
207-
3,
207+
$test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
208208
STREAM_CLIENT_CONNECT,
209209
$context
210210
);
@@ -283,7 +283,7 @@ function mail_try($test) {
283283
$method . '://' . $test['hostname'],
284284
$errno,
285285
$errstr,
286-
3,
286+
$test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
287287
STREAM_CLIENT_CONNECT,
288288
$context
289289
);
@@ -364,7 +364,7 @@ function mail_try($test) {
364364
$method . '://' . $test['hostname'],
365365
$errno,
366366
$errstr,
367-
3,
367+
$test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
368368
STREAM_CLIENT_CONNECT,
369369
$context
370370
);

includes/test_mqtt.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function mqtt_try($test) {
126126
CURLOPT_HEADER => true,
127127
CURLOPT_RETURNTRANSFER => true,
128128
CURLOPT_FILE => $file,
129-
CURLOPT_TIMEOUT => 7,
129+
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
130130
CURLOPT_NOPROGRESS => false,
131131
CURLOPT_XFERINFOFUNCTION => function ($download_size, $downloaded, $upload_size, $uploaded) {
132132
if ($downloaded > 0) {

includes/test_restapi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function restapi_try($test) {
4242
CURLOPT_RETURNTRANSFER => true,
4343
CURLOPT_FOLLOWLOCATION => true,
4444
CURLOPT_MAXREDIRS => 4,
45-
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 3) : 5,
45+
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 3) : read_config_option('servcheck_test_max_duration'),
4646
CURLOPT_CAINFO => $ca_info,
4747
];
4848

0 commit comments

Comments
 (0)