예제 #1
0
class MIB(coshsh.item.Item):
    id = 100
    template_rules = [
        TemplateRule(needsattr=None,
            template="check_logfiles_snmptt",
            self_name="mib",
            unique_attr="mib", unique_config="%s"),
    ]

    def __init__(self, **kwargs):
        super(self.__class__, self).__init__(kwargs)
        self.mib = kwargs["mib"]
        self.events = kwargs["events"]
        self.extcmd = kwargs.get("extcmd", "nagios.cmd")
        self.agents = {}

    def fingerprint(self):
        return self.mib

    def add_agent(self, agent):
        self.agents["%03d%03d%03d%03d" % tuple([int(n) for n in agent[0].split(".")])] = [agent[1], agent[2], agent[3]]

    def sort_agents(self):
        self.agent_ips = []
        self.service_pointers = []
        sortme = [(
            # ohne fuehrende 0, damit's richtig numerisch zugeht hier
            int("%d%03d%03d%03d" % tuple([int(n) for n in textwrap.wrap(str_ip, 3)])),
            str_ip
        ) for str_ip in self.agents.keys()]
        sortme.sort(key=lambda x: x[0])
        for num_ip, str_ip in sortme:
            self.agent_ips.append(num_ip)
            self.service_pointers.append(self.agents[str_ip])
예제 #2
0
class GenericApplication(Application):
    template_rules = [
        TemplateRule(needsattr=None,
                     template="app_generic_default",
                     unique_attr=['type', 'name'],
                     unique_config="app_%s_%s_default"),
    ]

    def __init__(self, params={}):
        super(GenericApplication, self).__init__(params)

    def render(self, template_cache, jinja2, recipe):
        # Maybe we find some processes, ports, filesystems in the
        # monitoring_details so we can output generic services
        if (hasattr(self, "processes") and self.processes) or (hasattr(
                self, "filesystems") and self.filesystems) or (hasattr(
                    self, "cfgfiles") and self.cfgfiles) or (hasattr(
                        self, "files") and self.files) or (hasattr(
                            self, "ports") and self.ports) or (hasattr(
                                self, "urls") and self.urls) or (hasattr(
                                    self, "services") and self.services):
            super(GenericApplication, self).render(template_cache, jinja2,
                                                   recipe)
        else:
            return ()
예제 #3
0
class CiscoIOS(Application):
    template_rules = [
        TemplateRule(
            needsattr=None,
            template="os_ios_default",
        ),
        TemplateRule(
            needsattr='interfaces',
            template="os_ios_if",
        ),
        TemplateRule(needsattr=None,
                     template="exporter",
                     suffix="json",
                     for_tool="prometheus",
                     unique_config="snmp_%s",
                     unique_attr="host_name"),
    ]
예제 #4
0
class HostInfoObj(coshsh.item.Item):
    id = 120
    template_rules = [
        TemplateRule(template="HostSNMPTrapinfo",
                     self_name="info",
                     suffix="pm"),
    ]

    def __init__(self, **kwargs):
        super(self.__class__, self).__init__(kwargs)

    def fingerprint(self):
        return "info"
예제 #5
0
class MIB(coshsh.item.Item):
    id = 100
    template_rules = [
        TemplateRule(needsattr=None,
                     template="check_logfiles_snmptt",
                     self_name="mib",
                     unique_attr="mib",
                     unique_config="%s"),
    ]

    def __init__(self, **kwargs):
        super(self.__class__, self).__init__(kwargs)
        self.mib = kwargs["mib"]
        self.events = kwargs["events"]
        self.extcmd = kwargs.get("extcmd", "nagios.cmd")

    def fingerprint(self):
        return self.mib
예제 #6
0
class RagpickerMIB(MIB):
    id = 101
    template_rules = [
        TemplateRule(needsattr=None,
                     template="check_logfiles_snmptt",
                     self_name="mib",
                     unique_attr="mib",
                     unique_config="%s"),
    ]

    def __init__(self, *args, **kwargs):
        super(self.__class__, self).__init__(**kwargs)
        self.ip_oid_combinations = []

    def add_ip_oid_combi(self, ip, oid):
        self.ip_oid_combinations.append(
            int(("%d%03d%03d%03d" % tuple([int(n) for n in ip.split(".")])) +
                oid.replace(".", "")))

    def sort_ip_oid_combis(self):
        self.ip_oid_combinations.sort()

    def add_agent(self, agent):
        self.agents["%03d%03d%03d%03d" %
                    tuple([int(n) for n in agent[0].split(".")])] = [
                        agent[1], agent[2], agent[3]
                    ]

    def sort_agents(self):
        self.agent_ips = []
        self.service_pointers = []
        sortme = [
            (
                # ohne fuehrende 0, damit's richtig numerisch zugeht hier
                int("%d%03d%03d%03d" %
                    tuple([int(n) for n in textwrap.wrap(str_ip, 3)])),
                str_ip) for str_ip in list(self.agents.keys())
        ]
        sortme.sort(key=lambda x: x[0])
        for num_ip, str_ip in sortme:
            self.agent_ips.append(num_ip)
            self.service_pointers.append(self.agents[str_ip])