Ejemplo n.º 1
0
    def getHosts(self, hostgroup):

        #self.host_counter = self.host_counter + 1

        hosts = {}

        for hostname, status, output in self.hoststatusDefinitions:         
 
            if hostname not in hostgroup.hostObjectIds:

                continue

            host = Host(hostname)
            host.setResult(Result(status, output))
            hosts[hostname] = host

        for hostname, description, status, output in self.servicestatusDefinitions:

            if hostname not in hostgroup.hostObjectIds:

                continue
            
            host = Host(hostname)

            service = Service(description)
            service.setResult(Result(status, output))
            hosts[hostname].addService(service)

        return hosts.values();
    def getHosts(self, group):

        #self.host_counter = self.host_counter + 1

        hosts = {}

        for hostname, status, output in self.hoststatusDefinitions:         
 
            if hostname not in group.hostObjectIds:

                continue

            host = Host(hostname)
            host.setResult(Result(status, output))
            hosts[hostname] = host

        for hostname, description, status, output in self.servicestatusDefinitions:

            if hostname not in group.hostObjectIds: continue
            if isinstance(group, Servicegroup) and description not in group.hostServiceObjectIds[hostname]: continue
            
            host = Host(hostname)

            service = Service(description)
            service.setResult(Result(status, output))
            hosts[hostname].addService(service)

        return hosts.values();
    def getHosts(self, group):

        #self.host_counter = self.host_counter + 1

        reString = '^' + '$|^'.join(group.hostObjectIds) + '$'
        queryString = "GET hosts\nColumns: host_name plugin_output state\nFilter: host_name ~ " + reString + "\n"
        lines = self.query(queryString)

        hosts = {}

        for line in lines:

            columns = line.split(';')
            hostname = columns[0]
            output = columns[1]
            status = int(columns[2])

            host = Host(hostname)
            host.setResult(Result(status, output))
            hosts[hostname] = host

        reString = '^' + '$|^'.join(group.hostObjectIds) + '$'
        queryString = "GET services\nColumns: host_name description plugin_output state\nFilter: host_name ~ " + reString + "\n"
        if isinstance(group, Servicegroup):

            descriptions = []
            for hostname in group.hostObjectIds:

                descriptions = descriptions + group.hostServiceObjectIds[
                    hostname]
            reString = '^' + '$|^'.join(descriptions) + '$'
            queryString = queryString + "Filter: description ~ " + reString + "\n"
        lines = self.query(queryString)

        for line in lines:

            columns = line.split(';')
            hostname = columns[0]
            description = columns[1]
            output = columns[2]
            status = int(columns[3])

            service = Service(description)
            service.setResult(Result(status, output))
            hosts[hostname].addService(service)

        return hosts.values()
    def getHosts(self, group):

        #self.host_counter = self.host_counter + 1

        reString = '^' + '$|^'.join(group.hostObjectIds) + '$'
        queryString = "GET hosts\nColumns: host_name plugin_output state\nFilter: host_name ~ " + reString + "\n"
        lines = self.query(queryString)

        hosts = {}

        for line in lines:

            columns = line.split(';')
            hostname = columns[0]
            output = columns[1]
            status = int(columns[2])

            host = Host(hostname)
            host.setResult(Result(status, output))
            hosts[hostname] = host

        reString = '^' + '$|^'.join(group.hostObjectIds) + '$'
        queryString = "GET services\nColumns: host_name description plugin_output state\nFilter: host_name ~ " + reString + "\n"
        if isinstance(group, Servicegroup):

            descriptions = []
            for hostname in group.hostObjectIds:

                descriptions = descriptions + group.hostServiceObjectIds[hostname]
            reString = '^' + '$|^'.join(descriptions) + '$'
            queryString = queryString + "Filter: description ~ " + reString + "\n" 
        lines = self.query(queryString)

        for line in lines:

            columns = line.split(';')
            hostname = columns[0]
            description = columns[1]
            output = columns[2]
            status = int(columns[3])

            service = Service(description)
            service.setResult(Result(status, output))
            hosts[hostname].addService(service)

        return hosts.values();
    def getHosts(self, group):

        try:
            cursor = self.connection.cursor()

            hosts = {}

            if len(group.hostObjectIds) == 0: return hosts

            # get a list of all hosts in hostgroup

            whereClause = '") OR (host_object_id="'.join(group.hostObjectIds)
            cursor.execute('SELECT host_object_id, display_name FROM ' +
                           self.prefix + '_hosts WHERE (host_object_id="' +
                           whereClause + '")')

            rows = cursor.fetchall()
            for row in rows:

                hosts[str(row[0])] = Host(row[1])

            # get host results

            if isinstance(group, Hostgroup):

                whereClause = '") OR (host_object_id="'.join(hosts.keys())
                cursor.execute(
                    'SELECT host_object_id, current_state, output FROM ' +
                    self.prefix + '_hoststatus WHERE(host_object_id="' +
                    whereClause + '")')

                rows = cursor.fetchall()
                for row in rows:

                    result = Result(row[1], row[2])
                    hosts[str(row[0])].setResult(result)

            # get service list

            services = {}

            whereClause = '") OR (host_object_id="'.join(hosts.keys())
            cursor.execute(
                'SELECT host_object_id, service_object_id, display_name FROM '
                + self.prefix + '_services WHERE (host_object_id="' +
                whereClause + '")')

            rows = cursor.fetchall()

            for row in rows:

                service = Service(row[2])
                services[str(row[1])] = service

                if isinstance(group, Servicegroup) and str(
                        row[1]) not in group.hostServiceObjectIds[str(row[0])]:
                    continue

                hosts[str(row[0])].addService(service)

            # get service results

            whereClause = '") OR (service_object_id="'.join(services.keys())
            cursor.execute(
                'SELECT service_object_id, current_state, output FROM ' +
                self.prefix + '_servicestatus WHERE (service_object_id="' +
                whereClause + '")')
            rows = cursor.fetchall()

            for row in rows:

                result = Result(row[1], row[2])
                services[str(row[0])].setResult(result)

            cursor.close()
            return hosts.values()

        except MySQLdb.Error, e:

            self.connection.close()
            raise Exception("Could fetch host information from database: " +
                            str(e.args[1]))
Ejemplo n.º 6
0
                status = int(self.getDirective(definition,"current_state").strip())
                output = self.getDirective(definition,"plugin_output").strip()
                host = Host(hostname)
                host.setResult(Result(status, output))
                hosts[hostname] = host

        # get services

        services = {}
        regexp = 'servicestatus'+' \{([\S\s]*?)\}'
        pat = re.compile(regexp, re.DOTALL)
        definitions = pat.findall(content)

        for definition in definitions:

            hostname = self.getDirective(definition,"host_name").strip()

            if hostgroup == None or hostname in hostgroup.hostObjectIds:

                description = self.getDirective(definition,"service_description").strip()
                status = int(self.getDirective(definition,"current_state").strip())
                output = self.getDirective(definition,"plugin_output").strip()
                host = Host(hostname)

                service = Service(description)
                service.setResult(Result(status, output))
                hosts[hostname].addService(service)

        return hosts.values();