Created
September 16, 2013 09:57
-
-
Save garethr/6578735 to your computer and use it in GitHub Desktop.
Example of parsing the rkhunter output in Python, and creating metrics for each check in Librato Metrics.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rkhunter --check --nocolors --no-mail-on-warning --skip-keypress --no-summary | rkhunter-librato.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import fileinput | |
import librato | |
USER = os.environ['LIBRATO_USER'] | |
PASSWORD = os.environ['LIBRATO_PASSWORD'] | |
ALLOWED = { | |
"Not found": 0, | |
"None found": 0, | |
"Not allowed": 0, | |
"OK": 0, | |
"Found": 1, | |
"Skipped": 1, | |
"Warning": 2, | |
} | |
api = librato.connect(USER, PASSWORD) | |
for line in fileinput.input(): | |
parts = line.split('[') | |
if len(parts) > 1: | |
name = parts[0].strip() | |
key = parts[0].strip().lower() | |
for component in [".", " ", "-", "/", "'", "(", ")", "`"]: | |
key = key.replace(component, "_") | |
value = parts[1].replace("]", "").strip() | |
if key and value: | |
numeric_value = ALLOWED[value] | |
if isinstance(numeric_value, int): | |
api.submit(key, numeric_value, description=name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment