https://github.com/madrisan/pyxymon
A simple Python module for writing xymon external scripts
https://github.com/madrisan/pyxymon
monitoring-plugins python-wrapper xymon
Last synced: 3 months ago
JSON representation
A simple Python module for writing xymon external scripts
- Host: GitHub
- URL: https://github.com/madrisan/pyxymon
- Owner: madrisan
- License: gpl-3.0
- Created: 2017-03-10T17:38:35.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2025-01-26T10:11:39.000Z (about 1 year ago)
- Last Synced: 2025-01-26T11:19:19.505Z (about 1 year ago)
- Topics: monitoring-plugins, python-wrapper, xymon
- Language: Python
- Homepage:
- Size: 46.9 KB
- Stars: 7
- Watchers: 5
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.codacy.com/app/madrisan/pyxymon?utm_source=github.com&utm_medium=referral&utm_content=madrisan/pyxymon&utm_campaign=Badge_Grade)
[](https://codeclimate.com/github/madrisan/pyxymon)
[](https://spdx.org/licenses/GPL-3.0.html)
# PyXymon
PyXymon is a simple Python module that can help you write Xymon external scripts in Python.
PyXymon provides some methods for rendering the messages you want to display in the Xymon web page and for sending them to the Xymon server.
PyXymon reads the required informations from the Xymon environment variables, so you do not need to add any extra configuration file.
## Installation
Just copy the file [`pyxymon.py`](https://raw.githubusercontent.com/madrisan/pyxymon/master/pyxymon.py)
in the xymon `ext` directory.
## Usage
Create a script `yourcheck.py` using the following schema:
```
#!/usr/bin/python
import os
import sys
import pyxymon as pymon
CHECK_NAME = 'yourcheck'
CHECK_VERSION = 1
def run_check():
"""Check the status of whatever you want..."""
xymon = pymon.XymonClient(CHECK_NAME)
check_script = os.path.basename(__file__)
# do your logic...
# you can set the criticity of the final xymon message by using:
# xymon.color = pymon.STATUS_WARNING
# or
# xymon.color = pymon.STATUS_CRITICAL
# The default criticity is set to 'pymon.STATUS_OK'
# Optionally you can set the LIFETIME (in minutes) using:
# xymon.lifetime = 15
xymon.title('Title in the xymon check page')
xymon.section('Section Title',
'Text containing the lines you want to display')
# You can add here other sections, if required.
xymon.footer(check_script, CHECK_VERSION)
xymon.send()
def main():
run_check()
if __name__ == '__main__':
main()
sys.exit(0)
```
Configure your extension module in the file `$XYMONCLIENTHOME/etc/xymonclient.cfg`.
```
[yourcheck]
ENVFILE $XYMONCLIENTHOME/etc/xymonclient.cfg
CMD $XYMONCLIENTHOME/ext/yourcheck.py
LOGFILE $XYMONCLIENTLOGS/yourcheck.log
INTERVAL 10m
```
You can find a full example [here](example/check_pacemaker.py).
> [!TIP]
>
> If you need to run your Python check with root privileges, just prefix the `CMD` directive in `xymonclient.cfg`
> with the `sudo` command:
>
> CMD sudo $XYMONCLIENTHOME/ext/yourcheck.py
>
> By default *sudo* does not preserve the environment variables exported by Xymon.
> To preserve the variables required by *PyXymon*, add the following lines to the *sudo* configuration:
>
> ```
> Defaults env_keep:xymon += "XYMSRV"
> Defaults env_keep:xymon += "XYMONDPORT"
> Defaults env_keep:xymon += "MACHINE"
> ```