linuxfabrik-lib 2.4.0__tar.gz → 3.0.0__tar.gz

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.
Files changed (57) hide show
  1. linuxfabrik_lib-3.0.0/PKG-INFO +244 -0
  2. linuxfabrik_lib-3.0.0/README.md +176 -0
  3. linuxfabrik_lib-3.0.0/args.py +275 -0
  4. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/base.py +204 -210
  5. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/cache.py +26 -17
  6. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/db_mysql.py +15 -7
  7. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/db_sqlite.py +78 -29
  8. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/disk.py +93 -47
  9. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/distro.py +47 -17
  10. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/dmidecode.py +27 -13
  11. linuxfabrik_lib-3.0.0/endoflifedate.py +5093 -0
  12. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/feedparser.py +11 -5
  13. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/globals.py +5 -5
  14. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/grassfish.py +6 -58
  15. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/huawei.py +23 -22
  16. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/human.py +229 -187
  17. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/icinga.py +64 -24
  18. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/infomaniak.py +7 -5
  19. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/jitsi.py +3 -3
  20. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/keycloak.py +2 -4
  21. linuxfabrik_lib-3.0.0/lftest.py +227 -0
  22. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/librenms.py +18 -16
  23. linuxfabrik_lib-3.0.0/linuxfabrik_lib.egg-info/PKG-INFO +244 -0
  24. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/linuxfabrik_lib.egg-info/SOURCES.txt +3 -1
  25. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/net.py +49 -38
  26. linuxfabrik_lib-3.0.0/nextcloud.py +99 -0
  27. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/nodebb.py +15 -14
  28. linuxfabrik_lib-3.0.0/powershell.py +72 -0
  29. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/psutil.py +6 -5
  30. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/pyproject.toml +37 -2
  31. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/qts.py +4 -5
  32. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/redfish.py +184 -64
  33. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/rocket.py +47 -29
  34. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/shell.py +44 -25
  35. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/smb.py +30 -21
  36. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/time.py +16 -14
  37. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/txt.py +187 -169
  38. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/uptimerobot.py +79 -32
  39. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/url.py +58 -21
  40. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/veeam.py +4 -5
  41. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/version.py +33 -17
  42. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/wildfly.py +14 -13
  43. linuxfabrik_lib-3.0.0/winrm.py +409 -0
  44. linuxfabrik_lib-2.4.0/PKG-INFO +0 -217
  45. linuxfabrik_lib-2.4.0/README.md +0 -173
  46. linuxfabrik_lib-2.4.0/args.py +0 -270
  47. linuxfabrik_lib-2.4.0/endoflifedate.py +0 -3722
  48. linuxfabrik_lib-2.4.0/lftest.py +0 -53
  49. linuxfabrik_lib-2.4.0/linuxfabrik_lib.egg-info/PKG-INFO +0 -217
  50. linuxfabrik_lib-2.4.0/powershell.py +0 -57
  51. linuxfabrik_lib-2.4.0/winrm.py +0 -137
  52. /linuxfabrik_lib-2.4.0/LICENSE.txt → /linuxfabrik_lib-3.0.0/LICENSE +0 -0
  53. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/__init__.py +0 -0
  54. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/linuxfabrik_lib.egg-info/dependency_links.txt +0 -0
  55. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/linuxfabrik_lib.egg-info/requires.txt +0 -0
  56. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/linuxfabrik_lib.egg-info/top_level.txt +0 -0
  57. {linuxfabrik_lib-2.4.0 → linuxfabrik_lib-3.0.0}/setup.cfg +0 -0
@@ -0,0 +1,244 @@
1
+ Metadata-Version: 2.4
2
+ Name: linuxfabrik-lib
3
+ Version: 3.0.0
4
+ Summary: Python libraries used in various Linuxfabrik projects, including the 'Linuxfabrik Monitoring Plugins' project.
5
+ Author-email: "Linuxfabrik GmbH, Zurich, Switzerland" <info@linuxfabrik.ch>
6
+ License: This is free and unencumbered software released into the public domain.
7
+
8
+ Anyone is free to copy, modify, publish, use, compile, sell, or
9
+ distribute this software, either in source code form or as a compiled
10
+ binary, for any purpose, commercial or non-commercial, and by any
11
+ means.
12
+
13
+ In jurisdictions that recognize copyright laws, the author or authors
14
+ of this software dedicate any and all copyright interest in the
15
+ software to the public domain. We make this dedication for the benefit
16
+ of the public at large and to the detriment of our heirs and
17
+ successors. We intend this dedication to be an overt act of
18
+ relinquishment in perpetuity of all present and future rights to this
19
+ software under copyright law.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27
+ OTHER DEALINGS IN THE SOFTWARE.
28
+
29
+ For more information, please refer to <http://unlicense.org/>
30
+ Project-URL: Homepage, https://github.com/Linuxfabrik/lib
31
+ Project-URL: Documentation, https://github.com/Linuxfabrik/lib/blob/master/README.md
32
+ Project-URL: Source, https://github.com/Linuxfabrik/lib
33
+ Project-URL: Tracker, https://github.com/Linuxfabrik/lib/issues
34
+ Project-URL: Download, https://github.com/Linuxfabrik/lib/releases
35
+ Keywords: lib,libs,monitoring,monitoring plugins,icinga,nagios
36
+ Classifier: Development Status :: 6 - Mature
37
+ Classifier: Intended Audience :: Developers
38
+ Classifier: Intended Audience :: Education
39
+ Classifier: Intended Audience :: Healthcare Industry
40
+ Classifier: Intended Audience :: Information Technology
41
+ Classifier: Intended Audience :: Manufacturing
42
+ Classifier: Intended Audience :: Other Audience
43
+ Classifier: Intended Audience :: Science/Research
44
+ Classifier: Intended Audience :: System Administrators
45
+ Classifier: Intended Audience :: Telecommunications Industry
46
+ Classifier: License :: OSI Approved :: The Unlicense (Unlicense)
47
+ Classifier: Natural Language :: English
48
+ Classifier: Operating System :: OS Independent
49
+ Classifier: Programming Language :: Python
50
+ Classifier: Programming Language :: Python :: 3
51
+ Classifier: Topic :: Software Development :: Libraries
52
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
53
+ Classifier: Topic :: System
54
+ Classifier: Topic :: System :: Monitoring
55
+ Classifier: Topic :: System :: Networking :: Monitoring
56
+ Requires-Python: >=3.9
57
+ Description-Content-Type: text/markdown
58
+ License-File: LICENSE
59
+ Requires-Dist: beautifulsoup4
60
+ Requires-Dist: lxml
61
+ Requires-Dist: netifaces
62
+ Requires-Dist: psutil
63
+ Requires-Dist: pymysql
64
+ Requires-Dist: PySmbClient
65
+ Requires-Dist: smbprotocol
66
+ Requires-Dist: xmltodict
67
+ Dynamic: license-file
68
+
69
+ <h1 align="center">
70
+ Linuxfabrik Python Libraries
71
+ </h1>
72
+ <p align="center">
73
+ Python 3.9+ modules for Linuxfabrik projects: DB access, SQLite KVS caching, WinRM, SMB, shell execution, 15+ API integrations (Icinga2, Veeam, Nextcloud, ...). Available on PyPI.
74
+ <span>&#8226;</span>
75
+ <b>made by <a href="https://linuxfabrik.ch/">Linuxfabrik</a></b>
76
+ </p>
77
+ <div align="center">
78
+
79
+ ![GitHub Stars](https://img.shields.io/github/stars/linuxfabrik/lib)
80
+ ![License](https://img.shields.io/github/license/linuxfabrik/lib)
81
+ ![Version](https://img.shields.io/github/v/release/linuxfabrik/lib?sort=semver)
82
+ [![PyPI](https://img.shields.io/pypi/v/linuxfabrik-lib)](https://pypi.org/project/linuxfabrik-lib/)
83
+ ![Python](https://img.shields.io/badge/Python-3.9+-3776ab)
84
+ ![GitHub Issues](https://img.shields.io/github/issues/linuxfabrik/lib)
85
+ [![GitHubSponsors](https://img.shields.io/github/sponsors/Linuxfabrik?label=GitHub%20Sponsors)](https://github.com/sponsors/Linuxfabrik)
86
+ [![PayPal](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7AW3VVX62TR4A&source=url)
87
+
88
+ </div>
89
+
90
+ <br />
91
+
92
+
93
+ # Linuxfabrik Python Libraries
94
+
95
+ A mature, production-grade Python library collection providing 35+ modules with 300+ functions for system administration, monitoring, and infrastructure automation. These libraries are used across several Linuxfabrik projects -- most prominently the [Linuxfabrik Monitoring Plugins](https://github.com/Linuxfabrik/monitoring-plugins) (Nagios/Icinga check plugins), but also in [ChecklistFabrik](https://github.com/Linuxfabrik/checklistfabrik) and other tools.
96
+
97
+ The library requires Python 3.9+ and runs on every platform.
98
+
99
+
100
+ ## Installation
101
+
102
+ Add `linuxfabrik-lib` as a dependency to your project, or install it manually:
103
+
104
+ ```bash
105
+ pip install --user linuxfabrik-lib
106
+ ```
107
+
108
+
109
+ ## Documentation
110
+
111
+ Full API documentation is available at [linuxfabrik.github.io/lib](https://linuxfabrik.github.io/lib/). It is automatically built and deployed on every push to `main`.
112
+
113
+
114
+ ## Design Principles
115
+
116
+ These libraries are built with a clear set of priorities:
117
+
118
+ * **Procedural by design.** The libraries deliberately use a procedural/functional style rather than object-oriented programming. Pure functions with explicit inputs and outputs are easier to read, test, and reason about. This is especially true for the most prominent use case -- monitoring plugins -- which are short-lived, linear processes with no complex state to manage over time, where unnecessary abstraction layers would add overhead without tangible benefit.
119
+ * **Broad compatibility.** Python 3.9+ is the minimum, ensuring the libraries work on RHEL 8 and every major distribution without requiring newer runtimes.
120
+ * **Cross-platform.** Core functions behave identically on Linux, Windows, and macOS. Platform-specific code (WinRM, PowerShell, SMB) is cleanly separated.
121
+ * **Minimal dependencies.** We avoid pulling in large dependency trees. External packages are used only when the alternative would be unreliable or significantly more complex.
122
+ * **Consistent error handling.** Most functions return `(success, result)` tuples. The caller decides whether to continue or exit -- the library never exits on its own. The `base.coe()` ("Continue or Exit") helper makes this pattern concise.
123
+ * **Automatic redaction.** Sensitive data (passwords, tokens, API keys) in error messages is automatically sanitized before output.
124
+ * **Nagios/Icinga conventions.** State constants, threshold evaluation, performance data formatting, and range parsing follow the [Monitoring Plugins Development Guidelines](https://www.monitoring-plugins.org/doc/guidelines.html).
125
+ * **Defensive defaults.** Functions use sensible timeouts, safe SSL settings, and locked-down defaults so that plugins work out of the box without extensive configuration.
126
+
127
+
128
+ ## Library Index
129
+
130
+
131
+ ### Core Utilities
132
+
133
+ | Module | Description | Key Functions |
134
+ |--------|-------------|---------------|
135
+ | **args.py** | Extends `argparse` with custom input types for monitoring thresholds and common parameters. | `csv()`, `float_or_none()`, `int_or_none()`, `number_unit_method()` |
136
+ | **base.py** | The central library for plugin development. Provides state evaluation, threshold comparison, performance data formatting, ASCII table output, and the `coe()` error-handling pattern. | `coe()`, `get_perfdata()`, `get_state()`, `get_table()`, `get_worst()`, `match_range()`, `oao()`, `state2str()` |
137
+ | **globals.py** | Defines the four Nagios/Icinga plugin states: `STATE_OK` (0), `STATE_WARN` (1), `STATE_CRIT` (2), `STATE_UNKNOWN` (3). | -- |
138
+ | **human.py** | Converts raw numbers and durations to human-readable representations and back. Supports binary/SI prefixes and Nagios range syntax with units. | `bytes2human()`, `human2bytes()`, `seconds2human()`, `human2seconds()`, `number2human()` |
139
+ | **lftest.py** | Test harness for running plugin unit tests against expected STDOUT/STDERR output files. | `test()` |
140
+ | **time.py** | Date/time conversions between UNIX epochs, ISO strings, datetime objects, and weekday names. Timezone-aware. | `epoch2iso()`, `now()`, `timestr2epoch()`, `timestrdiff()`, `utc_offset()` |
141
+ | **txt.py** | Text processing: encoding conversion, regex compilation, substring extraction, multi-line parsing, sensitive data redaction, and pluralization. | `sanitize_sensitive_data()`, `extract_str()`, `mltext2array()`, `to_text()`, `to_bytes()` |
142
+ | **version.py** | Software version parsing, comparison, and End-of-Life checking against [endoflife.date](https://endoflife.date). | `check_eol()`, `version()`, `version2float()` |
143
+
144
+
145
+ ### Data Access & Caching
146
+
147
+ | Module | Description | Key Functions |
148
+ |--------|-------------|---------------|
149
+ | **cache.py** | A simple SQLite-based key-value store with optional key expiration. Used for persisting state between plugin runs. | `get()`, `set()` |
150
+ | **db_mysql.py** | MySQL/MariaDB client with connection management, query execution, and privilege checking. | `connect()`, `select()`, `check_select_privileges()` |
151
+ | **db_sqlite.py** | Full SQLite interface: table/index creation, CRUD operations, CSV import, regex support, and automatic load computation for time-series data. | `connect()`, `select()`, `insert()`, `create_table()`, `compute_load()`, `import_csv()` |
152
+
153
+
154
+ ### System & OS
155
+
156
+ | Module | Description | Key Functions |
157
+ |--------|-------------|---------------|
158
+ | **disk.py** | File I/O, directory walking, CSV/environment file parsing, partition listing, device-mapper resolution, and file ownership lookup. | `read_file()`, `walk_directory()`, `grep_file()`, `read_csv()`, `get_real_disks()` |
159
+ | **distro.py** | Linux distribution detection. Returns normalized facts including distribution name, version, and Ansible-compatible `os_family`. | `get_distribution_facts()` |
160
+ | **dmidecode.py** | Parses `dmidecode` output into structured data. Extracts CPU, RAM, firmware, serial number, manufacturer, and model information. | `get_data()`, `cpu_type()`, `ram()`, `manufacturer()`, `model()`, `serno()` |
161
+ | **endoflifedate.py** | Bundled End-of-Life data from [endoflife.date](https://endoflife.date) for offline version checks when internet access is unavailable. | -- |
162
+ | **psutil.py** | Wrapper around `psutil` for retrieving mounted disk partitions with device, mount point, and filesystem type. | `get_partitions()` |
163
+ | **shell.py** | Subprocess execution with pipeline support, regex filtering, configurable locale, and timeout handling. Works on Linux and Windows. | `shell_exec()`, `get_command_output()` |
164
+
165
+
166
+ ### Networking & HTTP
167
+
168
+ | Module | Description | Key Functions |
169
+ |--------|-------------|---------------|
170
+ | **feedparser.py** | Parses Atom and RSS feeds from URLs using BeautifulSoup. | `parse()` |
171
+ | **net.py** | Low-level networking: TCP/UDP sockets, SSL connections, Unix domain sockets, public IP lookup, hostname validation, and CIDR conversion. | `fetch()`, `fetch_ssl()`, `fetch_socket()`, `get_public_ip()`, `is_valid_hostname()` |
172
+ | **url.py** | HTTP client for fetching HTML, JSON, or raw data. Supports GET/POST, Basic/Digest authentication, SSL/TLS options, custom headers, and proxy control. | `fetch()`, `fetch_json()`, `get_latest_version_from_github()`, `strip_tags()` |
173
+
174
+
175
+ ### Windows Integration
176
+
177
+ | Module | Description | Key Functions |
178
+ |--------|-------------|---------------|
179
+ | **powershell.py** | Executes PowerShell commands locally (on Windows hosts). | `run_ps()` |
180
+ | **smb.py** | Native SMB/CIFS file access: list, glob, and open files on remote shares with encryption support. | `glob()`, `open_file()` |
181
+ | **winrm.py** | Executes commands and PowerShell scripts on remote Windows hosts via WinRM. Supports Kerberos, NTLM, CredSSP, and JEA (Just Enough Administration). | `run_cmd()`, `run_ps()` |
182
+
183
+
184
+ ### API Integrations
185
+
186
+ | Module | Description | Key Functions |
187
+ |--------|-------------|---------------|
188
+ | **grassfish.py** | [Grassfish](https://www.grassfish.com/) digital signage REST API. | `fetch_json()` |
189
+ | **huawei.py** | Huawei storage system status parsing (controller models, health, LED status). | `get_controller_model()` |
190
+ | **icinga.py** | Icinga2 REST API client for querying services, setting acknowledgements, and managing downtimes. | `get_service()`, `set_ack()`, `set_downtime()`, `remove_downtime()` |
191
+ | **infomaniak.py** | [Infomaniak](https://www.infomaniak.com/) Swiss Backup REST API for events and backup products. | `get_events()`, `get_swiss_backup_products()` |
192
+ | **jitsi.py** | [Jitsi Meet](https://jitsi.org/) server statistics API. | `get_data()` |
193
+ | **keycloak.py** | [Keycloak](https://www.keycloak.org/) identity provider API with OIDC discovery and admin token management. | `discover_oidc_endpoints()`, `obtain_admin_token()`, `get_data()` |
194
+ | **librenms.py** | [LibreNMS](https://www.librenms.org/) monitoring API with state conversion. | `get_data()` |
195
+ | **nextcloud.py** | [Nextcloud](https://nextcloud.com/) OCC command execution. | `run_occ()` |
196
+ | **nodebb.py** | [NodeBB](https://nodebb.org/) forum API. | `get_data()` |
197
+ | **qts.py** | [QNAP QTS](https://www.qnap.com/) NAS API with authentication. | `get_auth_sid()` |
198
+ | **redfish.py** | [Redfish](https://www.dmtf.org/standards/redfish) BMC API for chassis, thermal, power, and storage monitoring. | `get_chassis()`, `get_thermal()`, `get_power()` |
199
+ | **rocket.py** | [Rocket.Chat](https://www.rocket.chat/) API for statistics, room management, and webhooks. | `get_token()`, `get_stats()`, `send2webhook()` |
200
+ | **uptimerobot.py** | [UptimeRobot](https://uptimerobot.com/) API for monitor and alert management. | `get_monitors()`, `new_monitor()`, `get_account_details()` |
201
+ | **veeam.py** | [Veeam](https://www.veeam.com/) Backup & Replication Enterprise Manager API. | `get_token()` |
202
+ | **wildfly.py** | [WildFly/JBoss](https://www.wildfly.org/) application server management API (standalone and domain mode). | `get_data()` |
203
+
204
+
205
+ ## Usage Example
206
+
207
+ A typical monitoring plugin using these libraries:
208
+
209
+ ```python
210
+ import lib.args
211
+ import lib.base
212
+ import lib.url
213
+ from lib.globals import (STATE_CRIT, STATE_OK, STATE_UNKNOWN, STATE_WARN)
214
+
215
+ def main():
216
+ # Parse arguments with custom threshold types
217
+ parser = lib.args.ArgumentParser()
218
+ parser.add_argument('--url', required=True)
219
+ parser.add_argument('--warning', type=lib.args.float_or_none, default=80)
220
+ parser.add_argument('--critical', type=lib.args.float_or_none, default=90)
221
+ args = parser.parse_args()
222
+
223
+ # Fetch data (coe = "Continue or Exit")
224
+ result = lib.base.coe(lib.url.fetch_json(args.url))
225
+
226
+ # Evaluate thresholds
227
+ state = lib.base.get_state(result['usage'], args.warning, args.critical)
228
+ perfdata = lib.base.get_perfdata('usage', result['usage'], '%', args.warning, args.critical, 0, 100)
229
+
230
+ # Output and exit
231
+ lib.base.oao('Usage is {}%'.format(result['usage']), state, perfdata)
232
+
233
+ if __name__ == '__main__':
234
+ main()
235
+ ```
236
+
237
+
238
+ ## Tips & Tricks
239
+
240
+ Count the function calls to any "lib" library in your project and sort by frequency:
241
+
242
+ ```bash
243
+ grep -rhoP '\Wlib\.[a-zA-Z0-9_\.]+' * | sed 's/^[^a-zA-Z0-9]*//' | sort | uniq -c | sort -nr
244
+ ```
@@ -0,0 +1,176 @@
1
+ <h1 align="center">
2
+ Linuxfabrik Python Libraries
3
+ </h1>
4
+ <p align="center">
5
+ Python 3.9+ modules for Linuxfabrik projects: DB access, SQLite KVS caching, WinRM, SMB, shell execution, 15+ API integrations (Icinga2, Veeam, Nextcloud, ...). Available on PyPI.
6
+ <span>&#8226;</span>
7
+ <b>made by <a href="https://linuxfabrik.ch/">Linuxfabrik</a></b>
8
+ </p>
9
+ <div align="center">
10
+
11
+ ![GitHub Stars](https://img.shields.io/github/stars/linuxfabrik/lib)
12
+ ![License](https://img.shields.io/github/license/linuxfabrik/lib)
13
+ ![Version](https://img.shields.io/github/v/release/linuxfabrik/lib?sort=semver)
14
+ [![PyPI](https://img.shields.io/pypi/v/linuxfabrik-lib)](https://pypi.org/project/linuxfabrik-lib/)
15
+ ![Python](https://img.shields.io/badge/Python-3.9+-3776ab)
16
+ ![GitHub Issues](https://img.shields.io/github/issues/linuxfabrik/lib)
17
+ [![GitHubSponsors](https://img.shields.io/github/sponsors/Linuxfabrik?label=GitHub%20Sponsors)](https://github.com/sponsors/Linuxfabrik)
18
+ [![PayPal](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7AW3VVX62TR4A&source=url)
19
+
20
+ </div>
21
+
22
+ <br />
23
+
24
+
25
+ # Linuxfabrik Python Libraries
26
+
27
+ A mature, production-grade Python library collection providing 35+ modules with 300+ functions for system administration, monitoring, and infrastructure automation. These libraries are used across several Linuxfabrik projects -- most prominently the [Linuxfabrik Monitoring Plugins](https://github.com/Linuxfabrik/monitoring-plugins) (Nagios/Icinga check plugins), but also in [ChecklistFabrik](https://github.com/Linuxfabrik/checklistfabrik) and other tools.
28
+
29
+ The library requires Python 3.9+ and runs on every platform.
30
+
31
+
32
+ ## Installation
33
+
34
+ Add `linuxfabrik-lib` as a dependency to your project, or install it manually:
35
+
36
+ ```bash
37
+ pip install --user linuxfabrik-lib
38
+ ```
39
+
40
+
41
+ ## Documentation
42
+
43
+ Full API documentation is available at [linuxfabrik.github.io/lib](https://linuxfabrik.github.io/lib/). It is automatically built and deployed on every push to `main`.
44
+
45
+
46
+ ## Design Principles
47
+
48
+ These libraries are built with a clear set of priorities:
49
+
50
+ * **Procedural by design.** The libraries deliberately use a procedural/functional style rather than object-oriented programming. Pure functions with explicit inputs and outputs are easier to read, test, and reason about. This is especially true for the most prominent use case -- monitoring plugins -- which are short-lived, linear processes with no complex state to manage over time, where unnecessary abstraction layers would add overhead without tangible benefit.
51
+ * **Broad compatibility.** Python 3.9+ is the minimum, ensuring the libraries work on RHEL 8 and every major distribution without requiring newer runtimes.
52
+ * **Cross-platform.** Core functions behave identically on Linux, Windows, and macOS. Platform-specific code (WinRM, PowerShell, SMB) is cleanly separated.
53
+ * **Minimal dependencies.** We avoid pulling in large dependency trees. External packages are used only when the alternative would be unreliable or significantly more complex.
54
+ * **Consistent error handling.** Most functions return `(success, result)` tuples. The caller decides whether to continue or exit -- the library never exits on its own. The `base.coe()` ("Continue or Exit") helper makes this pattern concise.
55
+ * **Automatic redaction.** Sensitive data (passwords, tokens, API keys) in error messages is automatically sanitized before output.
56
+ * **Nagios/Icinga conventions.** State constants, threshold evaluation, performance data formatting, and range parsing follow the [Monitoring Plugins Development Guidelines](https://www.monitoring-plugins.org/doc/guidelines.html).
57
+ * **Defensive defaults.** Functions use sensible timeouts, safe SSL settings, and locked-down defaults so that plugins work out of the box without extensive configuration.
58
+
59
+
60
+ ## Library Index
61
+
62
+
63
+ ### Core Utilities
64
+
65
+ | Module | Description | Key Functions |
66
+ |--------|-------------|---------------|
67
+ | **args.py** | Extends `argparse` with custom input types for monitoring thresholds and common parameters. | `csv()`, `float_or_none()`, `int_or_none()`, `number_unit_method()` |
68
+ | **base.py** | The central library for plugin development. Provides state evaluation, threshold comparison, performance data formatting, ASCII table output, and the `coe()` error-handling pattern. | `coe()`, `get_perfdata()`, `get_state()`, `get_table()`, `get_worst()`, `match_range()`, `oao()`, `state2str()` |
69
+ | **globals.py** | Defines the four Nagios/Icinga plugin states: `STATE_OK` (0), `STATE_WARN` (1), `STATE_CRIT` (2), `STATE_UNKNOWN` (3). | -- |
70
+ | **human.py** | Converts raw numbers and durations to human-readable representations and back. Supports binary/SI prefixes and Nagios range syntax with units. | `bytes2human()`, `human2bytes()`, `seconds2human()`, `human2seconds()`, `number2human()` |
71
+ | **lftest.py** | Test harness for running plugin unit tests against expected STDOUT/STDERR output files. | `test()` |
72
+ | **time.py** | Date/time conversions between UNIX epochs, ISO strings, datetime objects, and weekday names. Timezone-aware. | `epoch2iso()`, `now()`, `timestr2epoch()`, `timestrdiff()`, `utc_offset()` |
73
+ | **txt.py** | Text processing: encoding conversion, regex compilation, substring extraction, multi-line parsing, sensitive data redaction, and pluralization. | `sanitize_sensitive_data()`, `extract_str()`, `mltext2array()`, `to_text()`, `to_bytes()` |
74
+ | **version.py** | Software version parsing, comparison, and End-of-Life checking against [endoflife.date](https://endoflife.date). | `check_eol()`, `version()`, `version2float()` |
75
+
76
+
77
+ ### Data Access & Caching
78
+
79
+ | Module | Description | Key Functions |
80
+ |--------|-------------|---------------|
81
+ | **cache.py** | A simple SQLite-based key-value store with optional key expiration. Used for persisting state between plugin runs. | `get()`, `set()` |
82
+ | **db_mysql.py** | MySQL/MariaDB client with connection management, query execution, and privilege checking. | `connect()`, `select()`, `check_select_privileges()` |
83
+ | **db_sqlite.py** | Full SQLite interface: table/index creation, CRUD operations, CSV import, regex support, and automatic load computation for time-series data. | `connect()`, `select()`, `insert()`, `create_table()`, `compute_load()`, `import_csv()` |
84
+
85
+
86
+ ### System & OS
87
+
88
+ | Module | Description | Key Functions |
89
+ |--------|-------------|---------------|
90
+ | **disk.py** | File I/O, directory walking, CSV/environment file parsing, partition listing, device-mapper resolution, and file ownership lookup. | `read_file()`, `walk_directory()`, `grep_file()`, `read_csv()`, `get_real_disks()` |
91
+ | **distro.py** | Linux distribution detection. Returns normalized facts including distribution name, version, and Ansible-compatible `os_family`. | `get_distribution_facts()` |
92
+ | **dmidecode.py** | Parses `dmidecode` output into structured data. Extracts CPU, RAM, firmware, serial number, manufacturer, and model information. | `get_data()`, `cpu_type()`, `ram()`, `manufacturer()`, `model()`, `serno()` |
93
+ | **endoflifedate.py** | Bundled End-of-Life data from [endoflife.date](https://endoflife.date) for offline version checks when internet access is unavailable. | -- |
94
+ | **psutil.py** | Wrapper around `psutil` for retrieving mounted disk partitions with device, mount point, and filesystem type. | `get_partitions()` |
95
+ | **shell.py** | Subprocess execution with pipeline support, regex filtering, configurable locale, and timeout handling. Works on Linux and Windows. | `shell_exec()`, `get_command_output()` |
96
+
97
+
98
+ ### Networking & HTTP
99
+
100
+ | Module | Description | Key Functions |
101
+ |--------|-------------|---------------|
102
+ | **feedparser.py** | Parses Atom and RSS feeds from URLs using BeautifulSoup. | `parse()` |
103
+ | **net.py** | Low-level networking: TCP/UDP sockets, SSL connections, Unix domain sockets, public IP lookup, hostname validation, and CIDR conversion. | `fetch()`, `fetch_ssl()`, `fetch_socket()`, `get_public_ip()`, `is_valid_hostname()` |
104
+ | **url.py** | HTTP client for fetching HTML, JSON, or raw data. Supports GET/POST, Basic/Digest authentication, SSL/TLS options, custom headers, and proxy control. | `fetch()`, `fetch_json()`, `get_latest_version_from_github()`, `strip_tags()` |
105
+
106
+
107
+ ### Windows Integration
108
+
109
+ | Module | Description | Key Functions |
110
+ |--------|-------------|---------------|
111
+ | **powershell.py** | Executes PowerShell commands locally (on Windows hosts). | `run_ps()` |
112
+ | **smb.py** | Native SMB/CIFS file access: list, glob, and open files on remote shares with encryption support. | `glob()`, `open_file()` |
113
+ | **winrm.py** | Executes commands and PowerShell scripts on remote Windows hosts via WinRM. Supports Kerberos, NTLM, CredSSP, and JEA (Just Enough Administration). | `run_cmd()`, `run_ps()` |
114
+
115
+
116
+ ### API Integrations
117
+
118
+ | Module | Description | Key Functions |
119
+ |--------|-------------|---------------|
120
+ | **grassfish.py** | [Grassfish](https://www.grassfish.com/) digital signage REST API. | `fetch_json()` |
121
+ | **huawei.py** | Huawei storage system status parsing (controller models, health, LED status). | `get_controller_model()` |
122
+ | **icinga.py** | Icinga2 REST API client for querying services, setting acknowledgements, and managing downtimes. | `get_service()`, `set_ack()`, `set_downtime()`, `remove_downtime()` |
123
+ | **infomaniak.py** | [Infomaniak](https://www.infomaniak.com/) Swiss Backup REST API for events and backup products. | `get_events()`, `get_swiss_backup_products()` |
124
+ | **jitsi.py** | [Jitsi Meet](https://jitsi.org/) server statistics API. | `get_data()` |
125
+ | **keycloak.py** | [Keycloak](https://www.keycloak.org/) identity provider API with OIDC discovery and admin token management. | `discover_oidc_endpoints()`, `obtain_admin_token()`, `get_data()` |
126
+ | **librenms.py** | [LibreNMS](https://www.librenms.org/) monitoring API with state conversion. | `get_data()` |
127
+ | **nextcloud.py** | [Nextcloud](https://nextcloud.com/) OCC command execution. | `run_occ()` |
128
+ | **nodebb.py** | [NodeBB](https://nodebb.org/) forum API. | `get_data()` |
129
+ | **qts.py** | [QNAP QTS](https://www.qnap.com/) NAS API with authentication. | `get_auth_sid()` |
130
+ | **redfish.py** | [Redfish](https://www.dmtf.org/standards/redfish) BMC API for chassis, thermal, power, and storage monitoring. | `get_chassis()`, `get_thermal()`, `get_power()` |
131
+ | **rocket.py** | [Rocket.Chat](https://www.rocket.chat/) API for statistics, room management, and webhooks. | `get_token()`, `get_stats()`, `send2webhook()` |
132
+ | **uptimerobot.py** | [UptimeRobot](https://uptimerobot.com/) API for monitor and alert management. | `get_monitors()`, `new_monitor()`, `get_account_details()` |
133
+ | **veeam.py** | [Veeam](https://www.veeam.com/) Backup & Replication Enterprise Manager API. | `get_token()` |
134
+ | **wildfly.py** | [WildFly/JBoss](https://www.wildfly.org/) application server management API (standalone and domain mode). | `get_data()` |
135
+
136
+
137
+ ## Usage Example
138
+
139
+ A typical monitoring plugin using these libraries:
140
+
141
+ ```python
142
+ import lib.args
143
+ import lib.base
144
+ import lib.url
145
+ from lib.globals import (STATE_CRIT, STATE_OK, STATE_UNKNOWN, STATE_WARN)
146
+
147
+ def main():
148
+ # Parse arguments with custom threshold types
149
+ parser = lib.args.ArgumentParser()
150
+ parser.add_argument('--url', required=True)
151
+ parser.add_argument('--warning', type=lib.args.float_or_none, default=80)
152
+ parser.add_argument('--critical', type=lib.args.float_or_none, default=90)
153
+ args = parser.parse_args()
154
+
155
+ # Fetch data (coe = "Continue or Exit")
156
+ result = lib.base.coe(lib.url.fetch_json(args.url))
157
+
158
+ # Evaluate thresholds
159
+ state = lib.base.get_state(result['usage'], args.warning, args.critical)
160
+ perfdata = lib.base.get_perfdata('usage', result['usage'], '%', args.warning, args.critical, 0, 100)
161
+
162
+ # Output and exit
163
+ lib.base.oao('Usage is {}%'.format(result['usage']), state, perfdata)
164
+
165
+ if __name__ == '__main__':
166
+ main()
167
+ ```
168
+
169
+
170
+ ## Tips & Tricks
171
+
172
+ Count the function calls to any "lib" library in your project and sort by frequency:
173
+
174
+ ```bash
175
+ grep -rhoP '\Wlib\.[a-zA-Z0-9_\.]+' * | sed 's/^[^a-zA-Z0-9]*//' | sort | uniq -c | sort -nr
176
+ ```