Skip to content

Commit f31c814

Browse files
committed
feat(infomaniak-swiss-backup-devices): add --ignore-customer, --ignore-name, --ignore-tag, --ignore-user parameters
1 parent 622bf54 commit f31c814

4 files changed

Lines changed: 127 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Monitoring Plugins:
3232

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`)
35+
* infomaniak-swiss-backup-devices: add `--ignore-customer`, `--ignore-name`, `--ignore-tag`, `--ignore-user` parameters to skip devices by regex
3536
* nextcloud-enterprise: provides information about an installed Nextcloud Enterprise subscription
3637
* statuspal: also detect 'emergency-maintenance' state
3738
* 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)

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ Links:
3333
```text
3434
usage: infomaniak-swiss-backup-devices [-h] [-V] --account-id ACCOUNT_ID
3535
[--always-ok] [-c CRIT] [--insecure]
36-
[--no-proxy] [--severity {warn,crit}]
36+
[--no-proxy]
37+
[--ignore-customer IGNORE_CUSTOMER]
38+
[--ignore-name IGNORE_NAME]
39+
[--ignore-tag IGNORE_TAG]
40+
[--ignore-user IGNORE_USER]
41+
[--severity {warn,crit}]
3742
[--timeout TIMEOUT] --token TOKEN
3843
[--test TEST] [-w WARN]
3944
@@ -50,6 +55,22 @@ options:
5055
--insecure This option explicitly allows to perform "insecure"
5156
SSL connections. Default: False
5257
--no-proxy Do not use a proxy. Default: False
58+
--ignore-customer IGNORE_CUSTOMER
59+
Any device whose product customer name matches this
60+
python regex will be ignored (repeating). Example:
61+
'(?i)test' for a case-insensitive search for "test".
62+
--ignore-name IGNORE_NAME
63+
Any device whose name matches this python regex will
64+
be ignored (repeating). Example: '(?i)old-backup' for
65+
a case-insensitive search for "old-backup".
66+
--ignore-tag IGNORE_TAG
67+
Any device whose product tag matches this python regex
68+
will be ignored (repeating). Example: '(?i)deprecated'
69+
for a case-insensitive search for "deprecated".
70+
--ignore-user IGNORE_USER
71+
Any device whose username matches this python regex
72+
will be ignored (repeating). Example: '(?i)testuser'
73+
for a case-insensitive search for "testuser".
5374
--severity {warn,crit}
5475
Severity for alerting other values. Default: warn
5576
--timeout TIMEOUT Network timeout in seconds. Default: 8 (seconds)

check-plugins/infomaniak-swiss-backup-devices/infomaniak-swiss-backup-devices

Lines changed: 69 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 each device / slot of all your Infomaniak Swiss backup products via the
3233
Infomaniak API."""
@@ -92,6 +93,46 @@ def parse_args():
9293
default=DEFAULT_NO_PROXY,
9394
)
9495

96+
parser.add_argument(
97+
'--ignore-customer',
98+
help='Any device whose product customer name matches this python regex will be ignored '
99+
'(repeating). '
100+
'Example: \'(?i)test\' for a case-insensitive search for "test".',
101+
action='append',
102+
default=None,
103+
dest='IGNORE_CUSTOMER',
104+
)
105+
106+
parser.add_argument(
107+
'--ignore-name',
108+
help='Any device whose name matches this python regex will be ignored '
109+
'(repeating). '
110+
'Example: \'(?i)old-backup\' for a case-insensitive search for "old-backup".',
111+
action='append',
112+
default=None,
113+
dest='IGNORE_NAME',
114+
)
115+
116+
parser.add_argument(
117+
'--ignore-tag',
118+
help='Any device whose product tag matches this python regex will be ignored '
119+
'(repeating). '
120+
'Example: \'(?i)deprecated\' for a case-insensitive search for "deprecated".',
121+
action='append',
122+
default=None,
123+
dest='IGNORE_TAG',
124+
)
125+
126+
parser.add_argument(
127+
'--ignore-user',
128+
help='Any device whose username matches this python regex will be ignored '
129+
'(repeating). '
130+
'Example: \'(?i)testuser\' for a case-insensitive search for "testuser".',
131+
action='append',
132+
default=None,
133+
dest='IGNORE_USER',
134+
)
135+
95136
parser.add_argument(
96137
'--severity',
97138
help='Severity for alerting other values. '
@@ -147,6 +188,16 @@ def main():
147188
except SystemExit:
148189
sys.exit(STATE_UNKNOWN)
149190

191+
# set default values for append parameters that were not specified
192+
if args.IGNORE_CUSTOMER is None:
193+
args.IGNORE_CUSTOMER = []
194+
if args.IGNORE_NAME is None:
195+
args.IGNORE_NAME = []
196+
if args.IGNORE_TAG is None:
197+
args.IGNORE_TAG = []
198+
if args.IGNORE_USER is None:
199+
args.IGNORE_USER = []
200+
150201
# fetch list of products
151202
if args.TEST is None:
152203
slots = lib.base.coe(lib.infomaniak.get_swiss_backup_slots(
@@ -166,10 +217,27 @@ def main():
166217
state = STATE_OK
167218
perfdata = ''
168219
table_data = []
220+
compiled_ignore_customer = [re.compile(item) for item in args.IGNORE_CUSTOMER]
221+
compiled_ignore_name = [re.compile(item) for item in args.IGNORE_NAME]
222+
compiled_ignore_tag = [re.compile(item) for item in args.IGNORE_TAG]
223+
compiled_ignore_user = [re.compile(item) for item in args.IGNORE_USER]
169224

170225
# analyze data
171226
for slot in slots:
172227
for slot_data in slot.get('data'):
228+
# ignore devices matching any --ignore-* parameter
229+
if any(item.search(slot.get('product_customer_name', '')) for item in compiled_ignore_customer): # pylint: disable=C0301
230+
continue
231+
if any(item.search(slot_data.get('customer_name', '')) for item in compiled_ignore_name):
232+
continue
233+
if any(
234+
item.search(tag['name'])
235+
for item in compiled_ignore_tag
236+
for tag in slot.get('product_tags', [])
237+
):
238+
continue
239+
if any(item.search(slot_data.get('username', '')) for item in compiled_ignore_user):
240+
continue
173241
if slot_data.get('storage_used', 0):
174242
used = round(slot_data.get('storage_used') / slot_data.get('size') * 100, 1)
175243
used_state = lib.base.get_state(used, args.WARN, args.CRIT)

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,40 @@ class TestCheck(unittest.TestCase):
7171
self.assertEqual(retc, STATE_CRIT)
7272

7373

74+
def test_if_check_runs_EXAMPLE02_ignore_customer(self):
75+
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'))
76+
self.assertIn('Everything is ok.', stdout)
77+
self.assertNotIn('99904', stdout)
78+
self.assertIn('99924', stdout)
79+
self.assertEqual(stderr, '')
80+
self.assertEqual(retc, STATE_OK)
81+
82+
def test_if_check_runs_EXAMPLE02_ignore_name(self):
83+
stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(self.check + ' --token=TOKEN --account-id=ACCOUNT-ID --ignore-name=\'^test$\' --test=stdout/EXAMPLE02,,0'))
84+
self.assertIn('Everything is ok.', stdout)
85+
self.assertNotIn('99925', stdout)
86+
self.assertNotIn('99931', stdout)
87+
self.assertNotIn('99945', stdout)
88+
self.assertIn('99924', stdout)
89+
self.assertEqual(stderr, '')
90+
self.assertEqual(retc, STATE_OK)
91+
92+
def test_if_check_runs_EXAMPLE02_ignore_tag(self):
93+
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'))
94+
self.assertIn('Everything is ok.', stdout)
95+
self.assertNotIn('99904', stdout)
96+
self.assertIn('99924', stdout)
97+
self.assertEqual(stderr, '')
98+
self.assertEqual(retc, STATE_OK)
99+
100+
def test_if_check_runs_EXAMPLE02_ignore_user(self):
101+
stdout, stderr, retc = lib.base.coe(lib.shell.shell_exec(self.check + ' --token=TOKEN --account-id=ACCOUNT-ID --ignore-user=\'SBI-AB123456\' --test=stdout/EXAMPLE02,,0'))
102+
self.assertIn('Everything is ok.', stdout)
103+
self.assertNotIn('99904', stdout)
104+
self.assertNotIn('99924', stdout)
105+
self.assertEqual(stderr, '')
106+
self.assertEqual(retc, STATE_OK)
107+
108+
74109
if __name__ == '__main__':
75110
unittest.main()

0 commit comments

Comments
 (0)