Build a real Scrippy script, step by step.
disk_watch.pyThroughout this tutorial, you will write disk_watch.py, a script that monitors the usage of filesystems and reports the result with an exit status compatible with monitoring tools such as Nagios, Icinga or Centreon.
The script starts as a few lines of code. Each step adds one Scrippy concept to it:
| Step | Concept | What disk_watch.py learns |
|---|---|---|
| 1 | First script | The declarative header and the execution context |
| 2 | Logging | Checking several mount points, with meaningful log levels |
| 3 | History | Returning a monitoring exit status and tracing every execution |
| 4 | Configuration file | Getting its mount points and thresholds from a validated configuration file |
| 5 | Options and arguments | Overriding the configuration from the command line |
| 6 | Secrets | Keeping an API token out of the logs |
| 7 | Workspace and environment | Writing a report file |
| 8 | Error handling | Handling unavailable mount points and invalid thresholds |
| 9 | Access control | Restricting its execution to the members of the ops group |
| 10 | Concurrent executions | Preventing simultaneous executions |
Then, the modules chapter extends disk_watch.py with each Scrippy module: Rendering the report from a template, checking remote servers over SSH, querying network appliances with SNMP, storing the measures in a database, sending alerts to an API, mailing the report and archiving it in a Git repository.
luiggi: The Scrippy directories are located in /home/luiggi/.local/share/scrippy. Adapt the paths to your own installation.~/tutorial, and run the script from there.Note: The code of each step is complete: You can copy it over the previous version of disk_watch.py.