Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/destrangis/urlmonitor
Check urls and run actions if changed
https://github.com/destrangis/urlmonitor
monitoring monitoring-application python web yaml
Last synced: 6 days ago
JSON representation
Check urls and run actions if changed
- Host: GitHub
- URL: https://github.com/destrangis/urlmonitor
- Owner: destrangis
- License: mit
- Created: 2019-05-05T22:25:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-11-19T12:31:15.000Z (almost 3 years ago)
- Last Synced: 2024-09-21T18:59:58.768Z (about 2 months ago)
- Topics: monitoring, monitoring-application, python, web, yaml
- Language: Python
- Size: 29.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## UrlMonitor
This program is intended to be run periodically from cron or a systemd ``.timer`` service on GNU/Linux, a Periodic Task on Windows, or whatever you are using.
When run, the program will check the URLs from its list, and, if they have changed since the last time they were checked, will run a series of actions as a result.
The list of URLs and actions to be run if changed are specified in a YAML file (by default called ``urllist.yml``). This file consist on a LIST of OBJECTS, each containing the fields name with a descriptive string, url with the url to be checked, and actions, which is a LIST of OBJECTS, where the key is the action name and the value are the arguments, which can be a STRING or a LIST of strings.
An example of urllist.yml file:
```yaml
---
- name: Check for new versions of my favourite software
url: https://www.coolproject.org/download/files
actions:
- email_notify:
- [email protected]
- [email protected]- name: Get latest version of the software
url: https://www.coolproject.org/latest
actions:
- re_match:
- '[Ss]ource [Tt]arball.*The file'
- run_script: wget {re_match[1]}
```
This action sets the following variables:Variable | Value
------------|-----------------------------------
return_code | The exit code of the program
error | The error encountered, if any
stdout | Whatever the program has written to its standard output
stderr | Whatever the program has written to its error output### Writing Custom Actions
You can write a custom action easily. You just need to write a Python module that exports a callable called ``action_object`` with the following signature:```python
def action_object(name, arglst, url, content, variables, log):
pass
```Where the arguments are:
Argument | Description
----------|--------
name | The action name
arglst | The list of arguments.
url | The url that changed
content | The content (possibly HTML) of the url
variables | A mapping containing the variables and their values
log | A logging objectIf the arguments in ``arglst`` will be expanded by the calling routine and should contain the final value.
If your action requires configuration parameters, you can create a class that has a ``__call__`` method and instantiate into ``action_object``. At configuration time, the program will call the ``initialise`` method with a dictionary containing the configuration parameters as argument.
In order to simplify the process, the module ``actionbase`` provides the class ``Action`` from which your action can inherit. This already provides an ``initialise`` method which will install the configuration parameters, which you can access as instance attributes of ``action_object``. In addition, you should provide a list of expected parameters and a default value for those that can have one in the class variables ``check_cfg_vars`` and ``default_vars``. An exception is raised if a parameter that has been specified in ``check_cfg_vars`` is not found and there is no default value.
As an example, you can check the code for the ``email_notify`` action.
```python
from urlmonitor.actionbase import Actionclass _EmailAction(Action):
check_cfg_vars = [ "smtp_server", "from_address", "smtp_encryption",
"smtp_user", "smtp_password", "smtp_port"]
default_vars = {
"from_address": "urlmonitor@{}".format(_NODE),
"smtp_encryption": None,
"smtp_user": None,
"smtp_password": "",
"smtp_port": 0,
}...
def __call__(self, name, arglst, url, content, variables, log):
...
action_object = _EmailAction()
```### License
This software is released under the **MIT License**