linuxfabrik-lib 2.0.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lib/__init__.py +1 -0
- lib/args.py +107 -0
- lib/base.py +695 -0
- lib/cache.py +144 -0
- lib/db_mysql.py +154 -0
- lib/db_sqlite.py +518 -0
- lib/disk.py +321 -0
- lib/distro.py +263 -0
- lib/dmidecode.py +233 -0
- lib/endoflifedate.py +2894 -0
- lib/feedparser.py +129 -0
- lib/globals.py +42 -0
- lib/grassfish.py +157 -0
- lib/huawei.py +563 -0
- lib/human.py +358 -0
- lib/icinga.py +225 -0
- lib/infomaniak.py +96 -0
- lib/jitsi.py +52 -0
- lib/keycloak.py +67 -0
- lib/lftest.py +42 -0
- lib/librenms.py +68 -0
- lib/net.py +297 -0
- lib/nodebb.py +34 -0
- lib/powershell.py +41 -0
- lib/psutil.py +41 -0
- lib/qts.py +80 -0
- lib/redfish.py +308 -0
- lib/rocket.py +82 -0
- lib/shell.py +165 -0
- lib/smb.py +85 -0
- lib/time.py +84 -0
- lib/txt.py +438 -0
- lib/url.py +188 -0
- lib/veeam.py +60 -0
- lib/version.py +252 -0
- lib/wildfly.py +44 -0
- lib/winrm.py +83 -0
- linuxfabrik_lib-2.0.0.0.dist-info/LICENSE.txt +24 -0
- linuxfabrik_lib-2.0.0.0.dist-info/METADATA +171 -0
- linuxfabrik_lib-2.0.0.0.dist-info/RECORD +42 -0
- linuxfabrik_lib-2.0.0.0.dist-info/WHEEL +5 -0
- linuxfabrik_lib-2.0.0.0.dist-info/top_level.txt +1 -0
lib/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# needed in order to be able to import from this directory
|
lib/args.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#! /usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8; py-indent-offset: 4 -*-
|
|
3
|
+
#
|
|
4
|
+
# Author: Linuxfabrik GmbH, Zurich, Switzerland
|
|
5
|
+
# Contact: info (at) linuxfabrik (dot) ch
|
|
6
|
+
# https://www.linuxfabrik.ch/
|
|
7
|
+
# License: The Unlicense, see LICENSE file.
|
|
8
|
+
|
|
9
|
+
# https://github.com/Linuxfabrik/monitoring-plugins/blob/main/CONTRIBUTING.rst
|
|
10
|
+
|
|
11
|
+
"""Extends argparse by new input argument data types on demand.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import re # pylint: disable=C0413
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
__author__ = 'Linuxfabrik GmbH, Zurich/Switzerland'
|
|
18
|
+
__version__ = '2024033101'
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def csv(arg):
|
|
22
|
+
"""Returns a list from a `csv` input argument.
|
|
23
|
+
"""
|
|
24
|
+
return [x.strip() for x in arg.split(',')]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def float_or_none(arg):
|
|
28
|
+
"""Returns None or float from a `float_or_none` input argument.
|
|
29
|
+
"""
|
|
30
|
+
if arg is None or str(arg).lower() == 'none':
|
|
31
|
+
return None
|
|
32
|
+
return float(arg)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def help(param):
|
|
36
|
+
"""Return global valid help text for a parameter.
|
|
37
|
+
"""
|
|
38
|
+
h = {
|
|
39
|
+
'--match':
|
|
40
|
+
'Uses Python regular expressions without any external flags like `re.IGNORECASE`. '
|
|
41
|
+
'The regular expression is applied to each line of the output. '
|
|
42
|
+
'Examples: '
|
|
43
|
+
'`(?i)example` to match the word "example" in a case-insensitive manner. '
|
|
44
|
+
'`^(?!.*example).*$` to match any string except "example" (negative lookahead). '
|
|
45
|
+
'`(?: ... )*` is a non-capturing group that matches any sequence of characters '
|
|
46
|
+
'that satisfy the condition inside it, zero or more times. ',
|
|
47
|
+
}
|
|
48
|
+
return h[param]
|
|
49
|
+
try:
|
|
50
|
+
return h[param]
|
|
51
|
+
except KeyError:
|
|
52
|
+
return ''
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def int_or_none(arg):
|
|
56
|
+
"""Returns None or int from a `int_or_none` input argument.
|
|
57
|
+
"""
|
|
58
|
+
if arg is None or str(arg).lower() == 'none':
|
|
59
|
+
return None
|
|
60
|
+
return int(arg)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def number_unit_method(arg, unit='%', method='USED'):
|
|
64
|
+
"""Expects '<number>[unit][method]. Useful for threshold arguments.
|
|
65
|
+
Number is an integer or float.
|
|
66
|
+
Unit is one of `%%|K|M|G|T|P`.
|
|
67
|
+
If "unit" is omitted, `%` is assumed.
|
|
68
|
+
`K` means `kibibyte` etc.
|
|
69
|
+
Method is one of `USED|FREE`.
|
|
70
|
+
If "method" is ommitted, `USED` is assumed.
|
|
71
|
+
Examples: '
|
|
72
|
+
* `95`: returns (95, '%', 'USED')
|
|
73
|
+
* `9.5M`: returns (9.5, 'M', 'USED')
|
|
74
|
+
* `95%USED`: returns (95, '%', 'USED')
|
|
75
|
+
* `5FREE`: : returns (5, '%', 'FREE')
|
|
76
|
+
* `5%FREE`: : returns (5, '%', 'FREE')
|
|
77
|
+
* `9.5GFREE`: returns (9.5, 'G', 'FREE')
|
|
78
|
+
* `1400GUSED`: returns (1400, 'G', 'USED')
|
|
79
|
+
"""
|
|
80
|
+
# use named groups in regex
|
|
81
|
+
regex = re.compile(
|
|
82
|
+
r'(?P<number>\d*\.?\d*)(?P<unit>%|K|M|G|T|P)?(?P<method>USED|FREE)?',
|
|
83
|
+
re.IGNORECASE,
|
|
84
|
+
)
|
|
85
|
+
match = re.search(regex, arg)
|
|
86
|
+
if match and match.groupdict().get('number'):
|
|
87
|
+
arg = match.groupdict().get('number').strip()
|
|
88
|
+
if match and match.groupdict().get('unit'):
|
|
89
|
+
unit = match.groupdict().get('unit').strip()
|
|
90
|
+
if match and match.groupdict().get('method'):
|
|
91
|
+
method = match.groupdict().get('method').strip()
|
|
92
|
+
return arg, unit.upper(), method.upper()
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def range_or_none(arg):
|
|
96
|
+
"""Returns None or range from a `range_or_none` input argument.
|
|
97
|
+
"""
|
|
98
|
+
return str_or_none(arg)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def str_or_none(arg):
|
|
102
|
+
"""Returns None or str from a `str_or_none` input argument.
|
|
103
|
+
"""
|
|
104
|
+
if arg is None or str(arg).lower() == 'none':
|
|
105
|
+
return None
|
|
106
|
+
return str(arg)
|
|
107
|
+
|