Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
* feature: Add cpu/memory statistics
* feature: Better process control
* feature: Add return data size stats
* feature: Add log renention
* feature: Add log retention
* feature: Command run only for selected tests
* feature: Add configurable test timeout
* feature: Add Servcheck graph template
* issue: Better themes support

--- 0.3 ---

Expand Down
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

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

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


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

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

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

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

Test duration - default test duration is 5 seconds, you can change it in settings. If you need different for
specific test, change "Long duration alert" parametr in test. After that the max. duration will be
Long duration alert + 2 seconds.

Recommendation for tests with download - please download only small not binary files.

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

For POP3 and IMAP tests is better insert correct username and password. Without credentials,
For POP3 and IMAP tests is better insert correct username and password. Without credentials,
curl can will return incorrect result.

SCP is in insecure mode - doesn't check SSH server key!
Expand Down
34 changes: 8 additions & 26 deletions includes/arrays.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,12 @@
];

$servcheck_states = [
'error' => [
'color' => '#FB4A14',
'display' => __('Error', 'servcheck')
],
'duration' => [
'color' => '#CDFDFF',
'display' => __('Long duration', 'servcheck')
],
'warning' => [
'color' => '#FCAA94',
'display' => __('Warning', 'servcheck')
],
'failing' => [
'color' => '#FAFD9E',
'display' => __('Failing', 'servcheck')
],
'ok' => [
'color' => '#E0FFE0',
'display' => __('Ok', 'servcheck')
],
'disabled' => [
'color' => '#CDCFC4',
'display' => __('Disabled', 'servcheck')
]
'error' => __('Error', 'servcheck'),
'duration' => __('Long duration', 'servcheck'),
'warning' => __('Warning', 'servcheck'),
'failing' => __('Failing', 'servcheck'),
'ok' => __('Ok', 'servcheck'),
'disabled' => __('Disabled', 'servcheck')
];

$service_types = [
Expand Down Expand Up @@ -555,7 +537,7 @@
'default' => 0,
'max_length' => '5',
'size' => '30',
'description' => __('If the test time is greater than this value more times in a row, send a notification. Related to variable Duration count.', 'servcheck'),
'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'),
'value' => '|arg1:duration_trigger|',
],
'duration_count' => [
Expand Down Expand Up @@ -936,7 +918,7 @@
'ftp_scp' => __('Encrypted SCP connection, login and try to download file specified in path (/path/to/file.txt).', 'servcheck'),
'smb_smb' => __('Try SMB protocol, username and password are required. Try to login and download file.', 'servcheck'),
'smb_smbs' => __('Try SMB protocol, username and password are required. Try to login and download file.', 'servcheck'),
'mqtt_mqtt' => __('Connetct to MQTT server and listen for any message. You can specify topic in Path (bedroom/temp), blank for any topic', 'servcheck'),
'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'),
'rest_basic' => __('REST API test with basic HTTP auth. Prepare credential first.', 'servcheck'),
'rest_apikey' => __('REST API test with API key auth. Prepare credential first.', 'servcheck'),
'rest_oauth2' => __('REST API test with Oauth2. Prepare credential first.', 'servcheck'),
Expand Down
9 changes: 8 additions & 1 deletion includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ function servcheck_check_debug() {
}
}

/**
* Log debug message
*
* @param string $message Text of the message that will be logged
*
* @return void
*/
function servcheck_debug($message = '') {
global $debug;

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

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

Expand Down
2 changes: 1 addition & 1 deletion includes/test_curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function curl_try($test) {
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 4,
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 1) : 5,
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
CURLOPT_CAINFO => $ca_info,
];

Expand Down
4 changes: 2 additions & 2 deletions includes/test_dns.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function dns_try($test) {

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

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

if (!cacti_sizeof($a->arrMX)) {
$results['result'] = 'error';
Expand Down Expand Up @@ -117,7 +117,7 @@ function doh_try($test) {
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 4,
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 3) : 5,
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
CURLOPT_CAINFO => $ca_info,
];

Expand Down
2 changes: 1 addition & 1 deletion includes/test_ftp.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function ftp_try($test) {
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 4,
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 1) : 5,
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
CURLOPT_CAINFO => $ca_info,
];

Expand Down
10 changes: 5 additions & 5 deletions includes/test_mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function mail_try($test) {
'tcp://' . $test['hostname'],
$errno,
$errstr,
3,
$test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
STREAM_CLIENT_CONNECT,
$context
);
Expand Down Expand Up @@ -153,7 +153,7 @@ function mail_try($test) {
'ssl://' . $test['hostname'],
$errno,
$errstr,
3,
$test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
STREAM_CLIENT_CONNECT,
$context
);
Expand Down Expand Up @@ -204,7 +204,7 @@ function mail_try($test) {
'tcp://' . $test['hostname'],
$errno,
$errstr,
3,
$test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
STREAM_CLIENT_CONNECT,
$context
);
Expand Down Expand Up @@ -283,7 +283,7 @@ function mail_try($test) {
$method . '://' . $test['hostname'],
$errno,
$errstr,
3,
$test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
STREAM_CLIENT_CONNECT,
$context
);
Expand Down Expand Up @@ -364,7 +364,7 @@ function mail_try($test) {
$method . '://' . $test['hostname'],
$errno,
$errstr,
3,
$test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
STREAM_CLIENT_CONNECT,
$context
);
Expand Down
2 changes: 1 addition & 1 deletion includes/test_mqtt.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function mqtt_try($test) {
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FILE => $file,
CURLOPT_TIMEOUT => 7,
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'),
CURLOPT_NOPROGRESS => false,
CURLOPT_XFERINFOFUNCTION => function ($download_size, $downloaded, $upload_size, $uploaded) {
if ($downloaded > 0) {
Expand Down
2 changes: 1 addition & 1 deletion includes/test_restapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function restapi_try($test) {
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_MAXREDIRS => 4,
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 3) : 5,
CURLOPT_TIMEOUT => $test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 3) : read_config_option('servcheck_test_max_duration'),
CURLOPT_CAINFO => $ca_info,
];

Expand Down
7 changes: 5 additions & 2 deletions includes/test_snmp.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function snmp_try($test) {

$version = 2;
$port = 161;
$timeout = ($test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration')) * 1000;

// default result
$results['result'] = 'error';
Expand Down Expand Up @@ -97,12 +98,14 @@ function snmp_try($test) {
servcheck_debug('SNMP GET request, hostname ' . $test['hostname'] . ':' . $port);
$data = cacti_snmp_get($test['hostname'], $credential['community'], $test['snmp_oid'], $version,
$credential['snmp_username'], $credential['snmp_password'], $credential['snmp_auth_protocol'],
$credential['snmp_priv_passphrase'], $credential['snmp_priv_protocol'], $credential['snmp_context'], $port);
$credential['snmp_priv_passphrase'], $credential['snmp_priv_protocol'], $credential['snmp_context'],
$port, $timeout);
} else {
servcheck_debug('SNMP WALK request, hostname ' . $test['hostname'] . ':' . $port);
$data = cacti_snmp_walk($test['hostname'], $credential['community'], $test['snmp_oid'], $version,
$credential['snmp_username'], $credential['snmp_password'], $credential['snmp_auth_protocol'],
$credential['snmp_priv_passphrase'], $credential['snmp_priv_protocol'], $credential['snmp_context'], $port);
$credential['snmp_priv_passphrase'], $credential['snmp_priv_protocol'], $credential['snmp_context'],
$port, $timeout);

$data = var_export($data, true);
}
Expand Down
2 changes: 2 additions & 0 deletions includes/test_ssh.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ function ssh_try($test) {
$ssh->enableQuietMode();
}

$ssh->setTimeout($test['duration_trigger'] > 0 ? ($test['duration_trigger'] + 2) : read_config_option('servcheck_test_max_duration'));

if ($test['cred_id'] > 0) {
$cred = db_fetch_row_prepared('SELECT * FROM plugin_servcheck_credential WHERE id = ?',
[$test['cred_id']]);
Expand Down
Loading
Loading