lazyState is a simple Python class that allows you to track the state of something (anything!) and get an exit code based on supplied variables.
Here's the problem. You're using Sensu to monitor your infrastructure but you don't want to use the Sensu Plugin for one reason or another. Maybe it's because you're re-writing your checks in Python instead of Ruby and don't want to use the Python version of the plugin, or you simply want to make it easier to write quick checks - doesn't matter.
When you're not using the Sensu Plugin you don't have the ability to track how many times a check has failed, so you can't escalate warnings to critical alerts, and this is obviously not desirable. This is where lazyCheck comes in. Simply process your check in a manner that it returns success or failure then let lazyState do the rest.
Simply copy the lazystate.py to your /etc/sensu/plugins directory (or whatever else you're using lazyState for) and import it into your Python script.
#! /usr/bin/python
import sys
from lazystate import lazyState
- Perform a simple check.
- When you check for success or failure, include lazyState in the exit code.
#! /usr/bin/python
import sys
from lazystate import lazyState
if (check_succeeded == True):
print("The check succeeded!")
sys.exit( lazyState("my_check_name").updateState() )
else:
print("The check failed!")
sys.exit( lazyState("my_check_name", True).updateState() )
It's important to note that the check name ("my_check_name" in this example) MUST be a consistent string.
Additionally, some customization can be done by passing additional parameters into the lazyState class. These include:
- Fails before warning (default: 3)
- Fails before critical (default: 5)
- State file storage directory (default: /tmp/states)
- State file storage extension (default: .lazystate)
These are passed into the class as follows:
lazyState("my_check_name", True, 5, 10, "/tmp/lazystate", ".lzyst").updateState()
- Fork it.
- Create your feature branch using bugs/ or features/ prefix.
- Commit your changes.
- Push to the branch.
- Create a pull request with an explanation of your changes.
2016-05-02: Initial Release
- Hash file identifier.
- Handle argument passing better.
Written by Charlie O'Leary, inspired by Sensu.
MIT License