Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: fa14dc3f02
Fetching contributors…

Cannot retrieve contributors at this time

executable file 45 lines (38 sloc) 1.347 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#!/usr/bin/env python

import cgitb
cgitb.enable()

import os
import sys
import cgi

from nagcat.graph import Graph

def argv_to_cgi(argv, cgi_store):
    key=None
    for arg in argv:
        if arg.startswith("--"):
            if key:
                cgi_store.list.append(cgi.MiniFieldStorage(key, True))
            key = arg.replace("--", "", 1)
        else:
            if key:
                cgi_store.list.append(cgi.MiniFieldStorage(key, arg))
            key = None

def pull_cgi_data(cgi_store):
    """Pull data from CGI variables, validating the inputs."""
    assert 'host' in cgi_store, "Host parameter not found"
    assert 'rrd' in cgi_store, "RRD parameter not found"
    host = cgi_store.getfirst('host').translate(None, "/.")
    rrd = cgi_store.getfirst('rrd').translate(None, "/.")

    if 'period' in cgi_store:
        period = cgi_store.getfirst('period')
    else:
        period = "day"
    return (host, rrd, period)

### Execution
if __name__ == "__main__":
    cgi_store = cgi.FieldStorage()
    argv_to_cgi(sys.argv, cgi_store)
    (host, rrd, period) = pull_cgi_data(cgi_store)
    path = os.environ.get('NAGCAT_RRA_DIR', None)
    assert os.path.isdir(path), "Invalid NAGCAT_RRA_DIR %s" % path
    graph = Graph(path, host, rrd, period)
    sys.stdout.write("Content-Type: image/png\r\n\r\n%s" % graph.graph())
Something went wrong with that request. Please try again.