Esempio n. 1
0
    def _get_config(self, instance):
        required = ['mysql_host', 'mysql_user', 'rrd_path']
        for param in required:
            if not instance.get(param):
                raise Exception("Cacti instance missing %s. Skipping." % (param))

        host = instance.get('mysql_host')
        user = instance.get('mysql_user')
        password = instance.get('mysql_password', '') or ''
        db = instance.get('mysql_db', 'cacti')
        rrd_path = instance.get('rrd_path')
        whitelist = instance.get('rrd_whitelist')
        field_names = instance.get('field_names', ['ifName', 'dskDevice'])

        Config = namedtuple('Config', [
            'host',
            'user',
            'password',
            'db',
            'rrd_path',
            'whitelist',
            'field_names']
        )

        return Config(host, user, password, db, rrd_path, whitelist, field_names)
Esempio n. 2
0
    def _parse_proc_list(self, processes):
        def _compute_family(command):
            if command.startswith("["):
                return "kernel"
            else:
                return (command.split()[0]).split("/")[-1]

        PSLine = namedtuple("PSLine", "user,pid,pct_cpu,pct_mem,vsz,rss,tty,stat,started,time,command")

        self.start_snapshot()
        for line in processes:
            try:
                psl = PSLine(*line)
                self.add_to_snapshot(
                    [
                        psl.user,
                        float(psl.pct_cpu),
                        float(psl.pct_mem),
                        int(psl.vsz),
                        int(psl.rss),
                        _compute_family(psl.command),
                        1,
                    ]
                )
            except Exception:
                pass
        self.end_snapshot(group_by=self.group_by_family)
Esempio n. 3
0
    def _get_config(self, instance):
        required = ['mysql_host', 'mysql_user', 'rrd_path']
        for param in required:
            if not instance.get(param):
                raise Exception("Cacti instance missing %s. Skipping." % (param))

        host = instance.get('mysql_host')
        user = instance.get('mysql_user')
        password = instance.get('mysql_password', '') or ''
        db = instance.get('mysql_db', 'cacti')
        rrd_path = instance.get('rrd_path')
        whitelist = instance.get('rrd_whitelist')
        field_names = instance.get('field_names', ['ifName', 'dskDevice'])

        Config = namedtuple('Config', [
            'host',
            'user',
            'password',
            'db',
            'rrd_path',
            'whitelist',
            'field_names']
        )

        return Config(host, user, password, db, rrd_path, whitelist, field_names)
Esempio n. 4
0
    def _parse_proc_list(self, processes):
        def _compute_family(command):
            if command.startswith('['):
                return 'kernel'
            else:
                return (command.split()[0]).split('/')[-1]

        PSLine = namedtuple(
            "PSLine",
            "user,pid,pct_cpu,pct_mem,vsz,rss,tty,stat,started,time,command")

        self.start_snapshot()
        for line in processes:
            try:
                psl = PSLine(*line)
                self.add_to_snapshot([
                    psl.user,
                    float(psl.pct_cpu),
                    float(psl.pct_mem),
                    int(psl.vsz),
                    int(psl.rss),
                    _compute_family(psl.command), 1
                ])
            except:
                pass
        self.end_snapshot(group_by=self.group_by_family)
Esempio n. 5
0
import time
import re
from util import namedtuple, get_hostname
from utils import TailFile

# Event types we know about but decide to ignore in the parser
IGNORE_EVENT_TYPES = []

# fields order for each event type, as named tuples
EVENT_FIELDS = {
    'CURRENT HOST STATE':
    namedtuple('E_CurrentHostState',
               'host, event_state, event_soft_hard, return_code, payload'),
    'CURRENT SERVICE STATE':
    namedtuple(
        'E_CurrentServiceState',
        'host, check_name, event_state, event_soft_hard, return_code, payload'
    ),
    'SERVICE ALERT':
    namedtuple(
        'E_ServiceAlert',
        'host, check_name, event_state, event_soft_hard, return_code, payload'
    ),
    'PASSIVE SERVICE CHECK':
    namedtuple('E_PassiveServiceCheck',
               'host, check_name, return_code, payload'),
    'HOST ALERT':
    namedtuple('E_HostAlert',
               'host, event_state, event_soft_hard, return_code, payload'),

    # [1305744274] SERVICE NOTIFICATION: ops;ip-10-114-237-165;Metric ETL;ACKNOWLEDGEMENT (CRITICAL);notify-service-by-email;HTTP CRITICAL: HTTP/1.1 503 Service Unavailable - 394 bytes in 0.010 second response time;datadog;alq
Esempio n. 6
0
    from util import namedtuple

    url_fmt = "http://docs.google.com/spreadsheet/pub?key=%s&gid=%s&single=true&output=csv"

    try:
        # gid=8 for second worksheet
        url = url_fmt % (remap_doc_id, 8)
        result = fetch(url)
    except Exception, e:
        raise Exception("%s (%s)" % (e, url))

    logging.info("Loading domains")
    reader = csv.reader(StringIO.StringIO(result.content))
    headerline = reader.next()
    domains = {}
    Domain = namedtuple("Domain", headerline)
    for line in reader:
        if not line[0]:
            break
        domain = Domain(*line)
        data = dict(domain._asdict())
        domains[domain.code] = data
        logging.info("  %(code)s - %(name)s", data)

    try:
        # gid=9 for 3rd worksheet
        url = url_fmt % (remap_doc_id, 9)
        result = fetch(url)
    except Exception, e:
        raise Exception("%s (%s)" % (e, url))
Esempio n. 7
0
import time
import re
from util import namedtuple, get_hostname
from utils import TailFile

# Event types we know about but decide to ignore in the parser
IGNORE_EVENT_TYPES = []

# fields order for each event type, as named tuples
EVENT_FIELDS = {
    'CURRENT HOST STATE':       namedtuple('E_CurrentHostState', 'host, event_state, event_soft_hard, return_code, payload'),
    'CURRENT SERVICE STATE':    namedtuple('E_CurrentServiceState', 'host, check_name, event_state, event_soft_hard, return_code, payload'),
    'SERVICE ALERT':            namedtuple('E_ServiceAlert', 'host, check_name, event_state, event_soft_hard, return_code, payload'),
    'PASSIVE SERVICE CHECK':    namedtuple('E_PassiveServiceCheck', 'host, check_name, return_code, payload'),
    'HOST ALERT':               namedtuple('E_HostAlert', 'host, event_state, event_soft_hard, return_code, payload'),

    # [1305744274] SERVICE NOTIFICATION: ops;ip-10-114-237-165;Metric ETL;ACKNOWLEDGEMENT (CRITICAL);notify-service-by-email;HTTP CRITICAL: HTTP/1.1 503 Service Unavailable - 394 bytes in 0.010 second response time;datadog;alq
    'SERVICE NOTIFICATION':     namedtuple('E_ServiceNotification', 'contact, host, check_name, event_state, notification_type, payload'),

    # [1296509331] SERVICE FLAPPING ALERT: ip-10-114-97-27;cassandra JVM Heap;STARTED; Service appears to have started flapping (23.4% change >= 20.0% threshold)
    # [1296662511] SERVICE FLAPPING ALERT: ip-10-114-97-27;cassandra JVM Heap;STOPPED; Service appears to have stopped flapping (3.8% change < 5.0% threshold)
    'SERVICE FLAPPING ALERT':   namedtuple('E_FlappingAlert', 'host, check_name, flap_start_stop, payload'),

    # Reference for external commands: http://old.nagios.org/developerinfo/externalcommands/commandlist.php
    # Command Format:
    # ACKNOWLEDGE_SVC_PROBLEM;<host_name>;<service_description>;<sticky>;<notify>;<persistent>;<author>;<comment>
    # [1305832665] EXTERNAL COMMAND: ACKNOWLEDGE_SVC_PROBLEM;ip-10-202-161-236;Resources ETL;2;1;0;datadog;alq checking
    'ACKNOWLEDGE_SVC_PROBLEM': namedtuple('E_ServiceAck', 'host, check_name, sticky_ack, notify_ack, persistent_ack, ack_author, payload'),

    # Command Format:
    # ACKNOWLEDGE_HOST_PROBLEM;<host_name>;<sticky>;<notify>;<persistent>;<author>;<comment>
Esempio n. 8
0
import time
import re
from util import namedtuple, get_hostname
from utils import TailFile

# Event types we know about but decide to ignore in the parser
IGNORE_EVENT_TYPES = []

# fields order for each event type, as named tuples
EVENT_FIELDS = {
    'CURRENT HOST STATE':       namedtuple('E_CurrentHostState', 'host, event_state, event_soft_hard, return_code, payload'),
    'CURRENT SERVICE STATE':    namedtuple('E_CurrentServiceState', 'host, check_name, event_state, event_soft_hard, return_code, payload'),
    'SERVICE ALERT':            namedtuple('E_ServiceAlert', 'host, check_name, event_state, event_soft_hard, return_code, payload'),
    'PASSIVE SERVICE CHECK':    namedtuple('E_PassiveServiceCheck', 'host, check_name, return_code, payload'),
    'HOST ALERT':               namedtuple('E_HostAlert', 'host, event_state, event_soft_hard, return_code, payload'),

    # [1305744274] SERVICE NOTIFICATION: ops;ip-10-114-237-165;Metric ETL;ACKNOWLEDGEMENT (CRITICAL);notify-service-by-email;HTTP CRITICAL: HTTP/1.1 503 Service Unavailable - 394 bytes in 0.010 second response time;datadog;alq
    'SERVICE NOTIFICATION':     namedtuple('E_ServiceNotification', 'contact, host, check_name, event_state, notification_type, payload'),

    # [1296509331] SERVICE FLAPPING ALERT: ip-10-114-97-27;cassandra JVM Heap;STARTED; Service appears to have started flapping (23.4% change >= 20.0% threshold)
    # [1296662511] SERVICE FLAPPING ALERT: ip-10-114-97-27;cassandra JVM Heap;STOPPED; Service appears to have stopped flapping (3.8% change < 5.0% threshold)
    'SERVICE FLAPPING ALERT':   namedtuple('E_FlappingAlert', 'host, check_name, flap_start_stop, payload'),

    # Reference for external commands: http://old.nagios.org/developerinfo/externalcommands/commandlist.php
    # Command Format:
    # ACKNOWLEDGE_SVC_PROBLEM;<host_name>;<service_description>;<sticky>;<notify>;<persistent>;<author>;<comment>
    # [1305832665] EXTERNAL COMMAND: ACKNOWLEDGE_SVC_PROBLEM;ip-10-202-161-236;Resources ETL;2;1;0;datadog;alq checking
    'ACKNOWLEDGE_SVC_PROBLEM': namedtuple('E_ServiceAck', 'host, check_name, sticky_ack, notify_ack, persistent_ack, ack_author, payload'),

    # Command Format:
    # ACKNOWLEDGE_HOST_PROBLEM;<host_name>;<sticky>;<notify>;<persistent>;<author>;<comment>
Esempio n. 9
0
            return 0

    @staticmethod
    def append(args):
        l = []
        for arg in args:
            if type(arg) == type("") or type(arg) == type(u""):
                l.extend(arg.split(","))
            else:
                l.append(str(arg))

        return ",".join(list(set(l)))


MetricDescriptor = namedtuple('MetricDescriptor',['version','name','type','aggregator',
        'temporal_aggregator','server_aggregator','server_temporal_aggregator',
        'group_on','temporal_group_on'])
SnapshotDesc = namedtuple('SnapshotDesc',['version','fields'])

def SnapshotField(name,_type,aggregator=sum,temporal_aggregator=agg.avg,
                    server_aggregator=None,server_temporal_aggregator=None,
                    group_on = False, temporal_group_on = False):
    if server_aggregator is None:
        if _type == 'str':
            server_aggregator = agg.append
        else:
            server_aggregator = sum

    if server_temporal_aggregator is None:
        if _type == 'str':
            server_temporal_aggregator = agg.append
Esempio n. 10
0
            return 0

    @staticmethod
    def append(args):
        l = []
        for arg in args:
            if type(arg) == type("") or type(arg) == type(u""):
                l.extend(arg.split(","))
            else:
                l.append(str(arg))

        return ",".join(list(set(l)))


MetricDescriptor = namedtuple('MetricDescriptor',['version','name','type','aggregator',
        'temporal_aggregator','server_aggregator','server_temporal_aggregator',
        'group_on','temporal_group_on'])
SnapshotDesc = namedtuple('SnapshotDesc',['version','fields'])

def SnapshotField(name,_type,aggregator=sum,temporal_aggregator=agg.avg,
                    server_aggregator=None,server_temporal_aggregator=None,
                    group_on = False, temporal_group_on = False):
    if server_aggregator is None:
        if _type == 'str':
            server_aggregator = agg.append
        else:
            server_aggregator = sum

    if server_temporal_aggregator is None:
        if _type == 'str':
            server_temporal_aggregator = agg.append
Esempio n. 11
0
import time
import re
from util import namedtuple, get_hostname
from utils import TailFile

# Event types we know about but decide to ignore in the parser
IGNORE_EVENT_TYPES = []

# fields order for each event type, as named tuples
EVENT_FIELDS = {
    "CURRENT HOST STATE": namedtuple("E_CurrentHostState", "host, event_state, event_soft_hard, return_code, payload"),
    "CURRENT SERVICE STATE": namedtuple(
        "E_CurrentServiceState", "host, check_name, event_state, event_soft_hard, return_code, payload"
    ),
    "SERVICE ALERT": namedtuple(
        "E_ServiceAlert", "host, check_name, event_state, event_soft_hard, return_code, payload"
    ),
    "PASSIVE SERVICE CHECK": namedtuple("E_PassiveServiceCheck", "host, check_name, return_code, payload"),
    "HOST ALERT": namedtuple("E_HostAlert", "host, event_state, event_soft_hard, return_code, payload"),
    # [1305744274] SERVICE NOTIFICATION: ops;ip-10-114-237-165;Metric ETL;ACKNOWLEDGEMENT (CRITICAL);notify-service-by-email;HTTP CRITICAL: HTTP/1.1 503 Service Unavailable - 394 bytes in 0.010 second response time;datadog;alq
    "SERVICE NOTIFICATION": namedtuple(
        "E_ServiceNotification", "contact, host, check_name, event_state, notification_type, payload"
    ),
    # [1296509331] SERVICE FLAPPING ALERT: ip-10-114-97-27;cassandra JVM Heap;STARTED; Service appears to have started flapping (23.4% change >= 20.0% threshold)
    # [1296662511] SERVICE FLAPPING ALERT: ip-10-114-97-27;cassandra JVM Heap;STOPPED; Service appears to have stopped flapping (3.8% change < 5.0% threshold)
    "SERVICE FLAPPING ALERT": namedtuple("E_FlappingAlert", "host, check_name, flap_start_stop, payload"),
    # Reference for external commands: http://old.nagios.org/developerinfo/externalcommands/commandlist.php
    # Command Format:
    # ACKNOWLEDGE_SVC_PROBLEM;<host_name>;<service_description>;<sticky>;<notify>;<persistent>;<author>;<comment>
    # [1305832665] EXTERNAL COMMAND: ACKNOWLEDGE_SVC_PROBLEM;ip-10-202-161-236;Resources ETL;2;1;0;datadog;alq checking
    "ACKNOWLEDGE_SVC_PROBLEM": namedtuple(