Example #1
0
def get_data():
    for dc in mydc:
        #print dc, mydc[dc][0], mydc[dc][1]
        s = Socket(mydc[dc][1])
        s = Socket((mydc[dc][0], 6557))
        q = s.hosts.columns('name', 'custom_variable_values', 'contact_groups',
                            'contacts').filter('host_name = cscpapp73vm2')
        #q = s.hosts.columns('name', 'custom_variable_values','contact_groups','contacts')
        result = q.call()
        data_string = json.dumps(result)

        # For decoding change the JSON string into a JSON object
        jsonObject = json.loads(data_string)

        for data in jsonObject:
            JSONString = json.dumps(data)
            #print "string=",JSONString
            JSONDict = json.loads(JSONString)
            #Get name of host from JsonString
            host_name = JSONDict['name']
            #Get Tags from JsonString
            tags = JSONDict['custom_variable_values']
            contacts = JSONDict['contacts']
            contact_groups = JSONDict['contact_groups']
            print tags
            cmkdist = parse_data(tags, host_name, contacts, contact_groups)
Example #2
0
    def query_backend(self, backend, host=None):
        '''Query a livestatus backend'''
        hosts_request = Socket(backend['connection']).hosts.columns(
            backend['host_field'], backend['group_field'])

        if backend['host_filter'] is not None:
            hosts_request = hosts_request.filter(backend['host_filter'])

        if host is not None:
            hosts_request = hosts_request.filter('name = ' + host[0])

        hosts_request._columns += backend['fields']

        hosts = hosts_request.call()
        for host in hosts:
            hostname = host[backend['host_field']]
            hostgroups = host[backend['group_field']]
            if not isinstance(hostgroups, list):
                hostgroups = [hostgroups]
            self.add_host(hostname, 'all')
            self.add_host(hostname, backend['name'])
            for group in hostgroups:
                self.add_host(hostname, group)
            for field in backend['fields']:
                var_name = backend['var_prefix'] + field
                if hostname not in self.result['_meta']['hostvars']:
                    self.result['_meta']['hostvars'][hostname] = {}
                self.result['_meta']['hostvars'][hostname][var_name] = host[
                    field]
Example #3
0
    def query_backend(self, backend, host=None):
        '''Query a livestatus backend'''
        hosts_request = Socket(backend['connection']).hosts.columns(backend['host_field'], backend['group_field'])

        if backend['host_filter'] is not None:
            hosts_request = hosts_request.filter(backend['host_filter'])

        if host is not None:
            hosts_request = hosts_request.filter('name = ' + host[0])

        hosts_request._columns += backend['fields']

        hosts = hosts_request.call()
        for host in hosts:
            hostname = host[backend['host_field']]
            hostgroups = host[backend['group_field']]
            if not isinstance(hostgroups, list):
                hostgroups = [hostgroups]
            self.add_host(hostname, 'all')
            self.add_host(hostname, backend['name'])
            for group in hostgroups:
                self.add_host(hostname, group)
            for field in backend['fields']:
                var_name = backend['var_prefix'] + field
                if hostname not in self.result['_meta']['hostvars']:
                    self.result['_meta']['hostvars'][hostname] = {}
                self.result['_meta']['hostvars'][hostname][var_name] = host[field]
Example #4
0
def get_cmknewdata(host,dc):
	#q = s.hosts.columns('name', 'custom_variable_values','contact_groups','contacts').filter('host_name = cscpapp73vm2')
	if dc == "colo" or dc == "ggva" and host != "":
		s=Socket(mydc[dc][1])
		s=Socket((mydc[dc][0],6557))
		if host != "all":
			query = s.hosts.columns('name', 'custom_variable_values','contact_groups','contacts','state').filter('host_name = '+ host)
			querycmk(s,query)
		elif host == "all":
			query = s.hosts.columns('name', 'custom_variable_values','contact_groups','contacts','state')
			querycmk(s,query)	
		else:
			print "Wrong host"
	elif dc == "all":
		for dc in mydc:
			s=Socket(mydc[dc][1])
			s=Socket((mydc[dc][0],6557))
			query = s.hosts.columns('name', 'custom_variable_values','contact_groups','contacts','state')
			querycmk(s,query)	
	else:
		print "wrong dc"		
Example #5
0
def auth_probe(auth_id_list, update_id, op):
    """Autentica buscando um chat_id dentro de uma lista"""
    if str(update_id) in auth_id_list:
        # abre o socket Livestatus apenas depois da autenticacao
        # e apenas para as operacoes que precisam do socket
        if op in ('down'):
            s = Socket(('127.0.0.1', 50000))
            return True, s
        else:
            return True, False
    else:
        return False, False
def test_socket(socket_mock):
    socket_mock.return_value.makefile.return_value.read.return_value = (
        '[["name","groups","perf_data"],'
        '["hbops",["archlinux","linux","hashbang"],'
        '"rta=0.168000ms;1000.000000;3000.000000;0.000000 pl=0%;100;100;0"]]')
    s = Socket("/var/lib/icinga/rw/live")
    q = s.hosts
    r = q.call()
    expected = [{
        'name':
        'hbops',
        'groups': ['archlinux', 'linux', 'hashbang'],
        'perf_data':
        "rta=0.168000ms;1000.000000;3000.000000;0.000000 pl=0%;"
        "100;100;0",
    }]
    assert r == expected
    def ensure_connection(self):
        # load MonitoringServerInfo
        ms_info = self.get_ms_info()
        if ms_info is None:
            logger.info("Use default connection parameters.")
        else:
            self.__access_point, self.__port = self.__parse_url(ms_info.url)

        logger.info("Try to connection: Sv: %s" % self.__access_point)

        socket_arg = self.__access_point
        try:
            if self.__port:
                socket_arg = (socket_arg, self.__port)
            self.__socket = Socket(socket_arg)
            test_query = self.__socket.test
            test_query.call()
        except socket.error as (errno, msg):
            logger.error('Socket Error [%d]: %s' % (errno, msg))
            raise hap.Signal
Example #8
0
        for service in service_list:
            self.command("ACKNOWLEDGE_SVC_PROBLEM;" + service['host_name'] +
                         ";" + service['description'] + ";" + "1;1;1;" +
                         acknowledged_by + ";" + message + "\n")


if __name__ == "__main__":
    args = parse_input_arguments()
    templates = get_template_environment()
    autotask = OkAutoTask()
    backend = get_autotask_mapping(args.host_backend_name)
    socket_info = get_livestatus_connection(args.host_backend_address)
    livestatus_action = LiveStatusAction(args.host_backend_address)

    # Create live status socket from input data
    livestatus_socket = Socket(
        (socket_info['backend_host'], socket_info['backend_port']))

    # Query for non acknowlegded host issues
    host_statuses = query_livestatus_host_status(args.host_name,
                                                 livestatus_socket)

    # Query for non acknowlegded service issues
    host_service_statuses = query_livestatus_host_services(
        args.host_name, livestatus_socket)

    # Convert epoch time to date
    for hs in host_statuses:
        last_state_change_epoch = hs['last_state_change']
        last_state_change_date = time.strftime(
            '%Y-%m-%d %H:%M:%S', time.localtime(last_state_change_epoch))
        # Update field with datetime instead of epoch time