Skip to content

Instantly share code, notes, and snippets.

@garethr
Created September 16, 2013 09:57
Show Gist options
  • Save garethr/6578735 to your computer and use it in GitHub Desktop.
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.
rkhunter --check --nocolors --no-mail-on-warning --skip-keypress --no-summary | rkhunter-librato.py
#!/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