Skip to content

Commit 7d360aa

Browse files
committed
feat(infomaniak-swiss-backup-products): add --ignore-customer, --ignore-tag parameters
1 parent dbec5bf commit 7d360aa

File tree

5 files changed

+116
-8
lines changed

5 files changed

+116
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Monitoring Plugins:
3333
* by-ssh: add alerting on single numeric values
3434
* by-winrm: executes commands on remote Windows hosts by WinRM, supporting JEA (including the JEA endpoint via `--winrm-configuration-name`)
3535
* infomaniak-swiss-backup-devices: add `--ignore-customer`, `--ignore-name`, `--ignore-tag`, `--ignore-user` parameters to skip devices by regex
36+
* infomaniak-swiss-backup-products: add `--ignore-customer`, `--ignore-tag` parameters to skip products by regex
3637
* nextcloud-enterprise: provides information about an installed Nextcloud Enterprise subscription
3738
* statuspal: also detect 'emergency-maintenance' state
3839
* valkey-status: support user and password credentials [PR #954](https://github.com/Linuxfabrik/monitoring-plugins/pull/954), thanks to [Claudio Kuenzler](https://github.com/Napsty)
@@ -64,6 +65,7 @@ Monitoring Plugins:
6465

6566
* all plugins: ignore unknown arguments instead of generating an error (this helps with updating Icinga and Nagios service definitions considerably)
6667
* by-ssh, by-winrm, disk-usage, example, file-ownership, fs-ro, infomaniak-events, journald-query, logfile, matomo-reporting, mysql-logfile, php-status, pip-updates, systemd-unit: fix `append` parameters so that user-specified values replace defaults instead of being appended to them ([#540](https://github.com/Linuxfabrik/monitoring-plugins/issues/540))
68+
* disk-io: also monitor normalized iowait on Linux (100% = one fully I/O-saturated core)
6769
* file-count: stopping when number of files actually exceed thresholds, therefore dramatically faster for large directories
6870
* file-ownership: `--filename` now merges with the default file list instead of replacing it; use `--no-default-files` to check only user-supplied files
6971
* file-ownership: extend default file list with CIS benchmark-relevant files (login.defs, sudoers, sysctl, systemd, PAM, etc.)

check-plugins/infomaniak-swiss-backup-products/README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ Links:
3131

3232
```text
3333
usage: infomaniak-swiss-backup-products [-h] [-V] --account-id ACCOUNT_ID
34-
[--always-ok] [-c CRIT] [--insecure]
34+
[--always-ok] [-c CRIT]
35+
[--ignore-customer IGNORE_CUSTOMER]
36+
[--ignore-tag IGNORE_TAG] [--insecure]
3537
[--no-proxy] [--severity {warn,crit}]
3638
[--timeout TIMEOUT] --token TOKEN
3739
[--test TEST] [-w WARN]
@@ -46,6 +48,14 @@ options:
4648
--always-ok Always returns OK.
4749
-c, --critical CRIT Set the critical for the expiration date in days.
4850
Default: 3
51+
--ignore-customer IGNORE_CUSTOMER
52+
Any product whose customer name matches this python
53+
regex will be ignored (repeating). Example: '(?i)test'
54+
for a case-insensitive search for "test".
55+
--ignore-tag IGNORE_TAG
56+
Any product whose tag matches this python regex will
57+
be ignored (repeating). Example: '(?i)deprecated' for
58+
a case-insensitive search for "deprecated".
4959
--insecure This option explicitly allows to perform "insecure"
5060
SSL connections. Default: False
5161
--no-proxy Do not use a proxy. Default: False

check-plugins/infomaniak-swiss-backup-products/icingaweb2-module-director/infomaniak-swiss-backup-products.json

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
"--critical": {
1212
"value": "$infomaniak_swiss_backup_products_critical$"
1313
},
14+
"--ignore-customer": {
15+
"value": "$infomaniak_swiss_backup_products_ignore_customer$",
16+
"repeat_key": true
17+
},
18+
"--ignore-tag": {
19+
"value": "$infomaniak_swiss_backup_products_ignore_tag$",
20+
"repeat_key": true
21+
},
1422
"--insecure": {
1523
"set_if": "$infomaniak_swiss_backup_products_insecure$"
1624
},
@@ -70,13 +78,23 @@
7078
},
7179
{
7280
"datafield_id": 8,
73-
"is_required": "y",
81+
"is_required": "n",
7482
"var_filter": null
7583
},
7684
{
7785
"datafield_id": 9,
7886
"is_required": "n",
7987
"var_filter": null
88+
},
89+
{
90+
"datafield_id": 10,
91+
"is_required": "y",
92+
"var_filter": null
93+
},
94+
{
95+
"datafield_id": 11,
96+
"is_required": "n",
97+
"var_filter": null
8098
}
8199
],
82100
"imports": [],
@@ -133,6 +151,8 @@
133151
"criticality": "C",
134152
"infomaniak_swiss_backup_products_always_ok": false,
135153
"infomaniak_swiss_backup_products_critical": 3,
154+
"infomaniak_swiss_backup_products_ignore_customer": [],
155+
"infomaniak_swiss_backup_products_ignore_tag": [],
136156
"infomaniak_swiss_backup_products_insecure": false,
137157
"infomaniak_swiss_backup_products_no_proxy": false,
138158
"infomaniak_swiss_backup_products_severity": "warn",
@@ -198,6 +218,28 @@
198218
"uuid": "76a05455-b038-42f7-bce5-e5481d2bf5de"
199219
},
200220
"4": {
221+
"varname": "infomaniak_swiss_backup_products_ignore_customer",
222+
"caption": "Infomaniak Swiss Backup Products: Ignore Customer",
223+
"description": "Any product whose customer name matches this python regex will be ignored (repeating). Example: '(?i)test' for a case-insensitive search for \"test\".",
224+
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeArray",
225+
"format": null,
226+
"settings": {
227+
"visibility": "visible"
228+
},
229+
"uuid": "743a94ab-9bba-4879-8c3e-cec64eae5900"
230+
},
231+
"5": {
232+
"varname": "infomaniak_swiss_backup_products_ignore_tag",
233+
"caption": "Infomaniak Swiss Backup Products: Ignore Tag",
234+
"description": "Any product whose tag matches this python regex will be ignored (repeating). Example: '(?i)deprecated' for a case-insensitive search for \"deprecated\".",
235+
"datatype": "Icinga\\Module\\Director\\DataType\\DataTypeArray",
236+
"format": null,
237+
"settings": {
238+
"visibility": "visible"
239+
},
240+
"uuid": "1e326a1d-8fce-435b-bcb2-d4620ba9da60"
241+
},
242+
"6": {
201243
"varname": "infomaniak_swiss_backup_products_insecure",
202244
"caption": "Infomaniak Swiss Backup Products: Insecure?",
203245
"description": "This option explicitly allows to perform \"insecure\" SSL connections.",
@@ -206,7 +248,7 @@
206248
"settings": {},
207249
"uuid": "48300e2a-b48e-4bd0-8798-bff2644d501d"
208250
},
209-
"5": {
251+
"7": {
210252
"varname": "infomaniak_swiss_backup_products_no_proxy",
211253
"caption": "Infomaniak Swiss Backup Products: No Proxy?",
212254
"description": "Do not use a proxy.",
@@ -215,7 +257,7 @@
215257
"settings": {},
216258
"uuid": "c71a3e44-fa1d-4cce-a766-50860ed9d5a1"
217259
},
218-
"6": {
260+
"8": {
219261
"varname": "infomaniak_swiss_backup_products_severity",
220262
"caption": "Infomaniak Swiss Backup Products: Severity",
221263
"description": "Severity for alerting other values.",
@@ -228,7 +270,7 @@
228270
},
229271
"uuid": "3b29820b-fb09-4755-9f87-6b15484c1337"
230272
},
231-
"7": {
273+
"9": {
232274
"varname": "infomaniak_swiss_backup_products_timeout",
233275
"caption": "Infomaniak Swiss Backup Products: Timeout",
234276
"description": "Network timeout in seconds.",
@@ -239,7 +281,7 @@
239281
},
240282
"uuid": "68ca2a79-ca12-4b2c-a326-ba22479a4a50"
241283
},
242-
"8": {
284+
"10": {
243285
"varname": "infomaniak_swiss_backup_products_token",
244286
"caption": "Infomaniak Swiss Backup Products: Token",
245287
"description": "Infomaniak API token",
@@ -250,7 +292,7 @@
250292
},
251293
"uuid": "012e5339-a577-468a-9182-423b1005cee1"
252294
},
253-
"9": {
295+
"11": {
254296
"varname": "infomaniak_swiss_backup_products_warning",
255297
"caption": "Infomaniak Swiss Backup Products: Warning",
256298
"description": "Set the warning for the expiration date in days.",

check-plugins/infomaniak-swiss-backup-products/infomaniak-swiss-backup-products

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
import argparse # pylint: disable=C0413
1515
import json # pylint: disable=C0413
16+
import re # pylint: disable=C0413
1617
import sys # pylint: disable=C0413
1718

1819
import lib.args # pylint: disable=C0413
@@ -26,7 +27,7 @@ from lib.globals import (STATE_CRIT, STATE_OK, # pylint: disable=C0413
2627
STATE_UNKNOWN, STATE_WARN)
2728

2829
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
29-
__version__ = '2025100601'
30+
__version__ = '2026040701'
3031

3132
DESCRIPTION = """Checks your Infomaniak Swiss Backup product details via the Infomaniak API."""
3233

@@ -73,6 +74,26 @@ def parse_args():
7374
default=DEFAULT_CRIT,
7475
)
7576

77+
parser.add_argument(
78+
'--ignore-customer',
79+
help='Any product whose customer name matches this python regex will be ignored '
80+
'(repeating). '
81+
'Example: \'(?i)test\' for a case-insensitive search for "test".',
82+
action='append',
83+
default=None,
84+
dest='IGNORE_CUSTOMER',
85+
)
86+
87+
parser.add_argument(
88+
'--ignore-tag',
89+
help='Any product whose tag matches this python regex will be ignored '
90+
'(repeating). '
91+
'Example: \'(?i)deprecated\' for a case-insensitive search for "deprecated".',
92+
action='append',
93+
default=None,
94+
dest='IGNORE_TAG',
95+
)
96+
7697
parser.add_argument(
7798
'--insecure',
7899
help='This option explicitly allows to perform "insecure" SSL connections. '
@@ -146,6 +167,12 @@ def main():
146167
except SystemExit:
147168
sys.exit(STATE_UNKNOWN)
148169

170+
# set default values for append parameters that were not specified
171+
if args.IGNORE_CUSTOMER is None:
172+
args.IGNORE_CUSTOMER = []
173+
if args.IGNORE_TAG is None:
174+
args.IGNORE_TAG = []
175+
149176
# fetch data
150177
if args.TEST is None:
151178
result = lib.base.coe(lib.infomaniak.get_swiss_backup_products(
@@ -165,9 +192,20 @@ def main():
165192
state = STATE_OK
166193
perfdata = ''
167194
table_data = []
195+
compiled_ignore_customer = [re.compile(item) for item in args.IGNORE_CUSTOMER]
196+
compiled_ignore_tag = [re.compile(item) for item in args.IGNORE_TAG]
168197

169198
# analyze data
170199
for product in result.get('data', {}):
200+
# ignore products matching any --ignore-* parameter
201+
if any(item.search(product.get('customer_name', '')) for item in compiled_ignore_customer):
202+
continue
203+
if any(
204+
item.search(tag['name'])
205+
for item in compiled_ignore_tag
206+
for tag in product.get('tags', [])
207+
):
208+
continue
171209

172210
expired_at = product.get('expired_at') - lib.time.now(as_type='epoch')
173211
expired_at_state = lib.base.get_state(expired_at / 24 / 60 / 60, args.WARN, args.CRIT, _operator='le')

check-plugins/infomaniak-swiss-backup-products/unit-test/run

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ class TestCheck(unittest.TestCase):
6161
self.assertEqual(stderr, '')
6262
self.assertEqual(retc, STATE_CRIT)
6363

64+
def test_if_check_runs_EXAMPLE02_ignore_customer(self):
65+
stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(self.check + ' --token=TOKEN --account-id=ACCOUNT-ID --ignore-customer=\'BK-200999-1$\' --test=stdout/EXAMPLE02,,0'))
66+
self.assertIn('Everything is ok.', stdout)
67+
self.assertNotIn('34567', stdout)
68+
self.assertIn('26056', stdout)
69+
self.assertEqual(stderr, '')
70+
self.assertEqual(retc, STATE_OK)
71+
72+
def test_if_check_runs_EXAMPLE02_ignore_tag(self):
73+
stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(self.check + ' --token=TOKEN --account-id=ACCOUNT-ID --ignore-tag=\'^tag01$\' --test=stdout/EXAMPLE02,,0'))
74+
self.assertIn('Everything is ok.', stdout)
75+
self.assertNotIn('34567', stdout)
76+
self.assertIn('26056', stdout)
77+
self.assertEqual(stderr, '')
78+
self.assertEqual(retc, STATE_OK)
79+
6480

6581
if __name__ == '__main__':
6682
unittest.main()

0 commit comments

Comments
 (0)