Skip to content

Commit 8460eaf

Browse files
committed
Added support for only sepecified webhooks
1 parent 0415a6d commit 8460eaf

5 files changed

Lines changed: 62 additions & 18 deletions

File tree

.env.template

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
APP_NAME=MonitoringAbraFlexi
2+
APP_DEBUG=true
3+
MUTE=true
4+
5+
ABRAFLEXI_URL="https://demo.abraflexi.eu:5434"
6+
ABRAFLEXI_LOGIN="winstrom"
7+
ABRAFLEXI_PASSWORD="winstrom"
8+
ABRAFLEXI_COMPANY="demo"
9+
ABRAFLEXI_CUSTOMER="demo"
10+
11+
12+
EASE_LOGGER="console|syslog"

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ Example of [/etc/nagions/nrpe.d/abraflexi.cfg](debian/conf/abraflexi.cfg) :
4444

4545
```
4646
command[check_flexibe]=/usr/lib/nagios/plugins/check_abraflexi -f
47-
command[check_abraflexi_webhooks]=/usr/lib/nagios/plugins/check_abraflexi_webhooks -f
47+
command[check_abraflexi_webhooks]=/usr/lib/nagios/plugins/check_abraflexi_webhooks
48+
command[check_abraflexi_webhook1]=/usr/lib/nagios/plugins/check_abraflexi_webhooks -w https://site.tld/webhook.php
49+
command[check_abraflexi_webhook2]=/usr/lib/nagios/plugins/check_abraflexi_webhooks -w https://hook.integromat.com/xxxxxxxx
4850
```
4951

5052
Without -f swith the undergoing library php-abraflexi try to use Environment variables:

composer.json

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
"name": "vitexsoftware/monitoring-plugins-abraflexi",
33
"description": "Nagios/Icinga plugins for monitoring Czech Economic system AbraFlexi",
44
"type": "project",
5-
"require": {
6-
"spojenet/abraflexi": "2.0.x-dev"
7-
},
8-
"license": "GPL-2",
5+
"license": "MIT",
96
"authors": [
107
{
118
"name": "Vítězslav Dvořák",
@@ -15,20 +12,20 @@
1512
"require": {
1613
"spojenet/flexibee": "2.0.x-dev"
1714
},
15+
"autoload": {
16+
"psr-4": {
17+
"MPF\\": "src/MPF/"
18+
}
19+
},
1820
"autoload-dev": {
1921
"psr-4": {
20-
"Test\\Ease\\": "vendor/vitexsoftware/ease-core/tests/src/Ease",
22+
"Test\\Ease\\": "vendor/vitexsoftware/ease-core/tests/src/EaseCore/",
2123
"Test\\AbraFlexi\\": "vendor/spoje.net/abraflexi/testing/src/AbraFlexi/",
2224
"Test\\MPF\\": "tests/src/MPF"
2325
}
2426
},
2527
"require-dev": {
2628
"phpunit/phpunit": "^9"
2729
},
28-
"autoload": {
29-
"psr-4": {
30-
"MPF\\": "src/MPF/"
31-
}
32-
},
3330
"minimum-stability": "dev"
3431
}

src/MPF/Connector.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@
1616
*/
1717
class Connector extends \AbraFlexi\RW {
1818

19+
20+
/**
21+
* Check only this webhook
22+
* @var string
23+
*/
24+
public $webhook = null;
25+
26+
27+
/**
28+
* SetUp Object to be ready for work
29+
*
30+
* @param array $options Object Options ( user,password,authSessionId
31+
* company,url,evidence,
32+
* prefix,defaultUrlParams,debug,
33+
* detail,offline,filter,ignore404,nativeTypes
34+
* timeout,companyUrl,ver,throwException
35+
* webhook
36+
*/
37+
public function setUp(array $options = []) {
38+
parent::setUp($options);
39+
$this->setupProperty($options, 'webhook', 'ABRAFLEXI_WEBHOOK');
40+
}
41+
1942
/**
2043
* Parse Commandline
2144
*
@@ -31,6 +54,7 @@ public static function parseCmdline() {
3154
$shortopts .= "f:"; // Config
3255
$shortopts .= "d"; // Debug
3356
$shortopts .= "h"; // Help
57+
$shortopts .= "w"; // WebHook
3458

3559
$longopts = array(
3660
"server:", // Server
@@ -39,6 +63,7 @@ public static function parseCmdline() {
3963
"company:", // Company
4064
"file:", // Config file
4165
"debug", // Debug
66+
"webhook", // WebHook
4267
"help"
4368
);
4469
$options = getopt($shortopts, $longopts);
@@ -69,6 +94,13 @@ public static function parseCmdline() {
6994
$optionsParsed['password'] = $options['password'];
7095
}
7196

97+
if (array_key_exists('w', $options)) {
98+
$optionsParsed['webhook'] = $options['w'];
99+
}
100+
if (array_key_exists('webhook', $options)) {
101+
$optionsParsed['webhook'] = $options['webhook'];
102+
}
103+
72104
if (array_key_exists('f', $options)) {
73105
$optionsParsed['config'] = $options['f'] ? $options['f'] : '/etc/abraflexi/client.json';
74106
}
@@ -88,8 +120,8 @@ public static function parseCmdline() {
88120
$optionsParsed['debug'] = true;
89121
}
90122

91-
if (array_key_exists('help', $options) || array_key_exists('h', $options) ) {
92-
echo("Usage: " . basename($_SERVER['SCRIPT_NAME']) . " -s https://SERVER[:PORT] -u USERNAME -p PASSWORD -c COMPANY [-d debug]\n");
123+
if (array_key_exists('help', $options) || array_key_exists('h', $options)) {
124+
echo("Usage: " . basename($_SERVER['SCRIPT_NAME']) . " -s https://SERVER[:PORT] -u USERNAME -p PASSWORD -c COMPANY [-w WebHookURL] [-d debug]\n");
93125
exit;
94126
}
95127

src/check_abraflexi_webhooks.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,18 @@
2525
if (count($hooksdata)) {
2626
$message = count($hooksdata) . ' hook' . ( count($hooksdata) > 1 ? 's' : '' ) . ' found; ';
2727
foreach ($hooksdata as $hookdata) {
28-
$message .= ' ' . $hookdata['url'] . ' lastVersion: ' . $hookdata['lastVersion'];
29-
if (intval($hookdata['penalty'])) {
30-
$result = 'ERROR';
31-
$message .= ' penalty: ' . $hookdata['penalty'] . ' lastPenalty: ' . $hookdata['lastPenalty'];
28+
if (empty($checker->webhook) || ($checker->webhook == $hookdata['url'])) {
29+
$message .= ' ' . $hookdata['url'] . ' lastVersion: ' . $hookdata['lastVersion'];
30+
if (intval($hookdata['penalty'])) {
31+
$result = 'ERROR';
32+
$message .= ' penalty: ' . $hookdata['penalty'] . ' lastPenalty: ' . $hookdata['lastPenalty'];
33+
}
3234
}
3335
}
3436
} else {
3537
$result = 'WARNING';
3638
$message .= ' No Hooks defined! ';
3739
}
38-
3940
$message .= ' (' . $checker->getApiURL() . '/hooks)';
4041
}
4142

0 commit comments

Comments
 (0)