Exemple #1
0
def inventory_perf_data(site, hostlist):

    invent_check_list = []
    invent_service_dict = {}
    db = mongo_functions.mongo_db_conn(site, "nocout")
    for host in hostlist[0]:
        query = "GET hosts\nColumns: host_services\nFilter: host_name = %s\n" % (
            host)
        query_output = rrd_main.get_from_socket(site, query).strip()
        service_list = [
            service_name for service_name in query_output.split(',')
        ]
        for service in service_list:
            if service.endswith('_invent'):
                invent_check_list.append(service)

        for service in invent_check_list:
            query_string = "GET services\nColumns: service_state plugin_output host_address\nFilter: " + \
            "service_description = %s\nFilter: host_name = %s\nOutputFormat: json\n"    % (service,host)
            query_output = json.loads(
                rrd_main.get_from_socket(site, query_string).strip())
            plugin_output = str(query_output[0][1].split('- ')[1])
            service_state = (query_output[0][0])
            if service_state == 0:
                service_state = "OK"
            elif service_state == 1:
                service_state = "WARNING"
            elif service_state == 2:
                service_state = "CRITICAL"
            elif service_state == 3:
                service_state = "UNKNOWN"
            host_ip = str(query_output[0][2])
            current_time = int(time.time())
            invent_service_dict = dict(sys_timestamp=current_time,
                                       check_timestamp=current_time,
                                       device_name=str(host),
                                       service_name=service,
                                       current_value=plugin_output,
                                       min_value=0,
                                       max_value=0,
                                       avg_value=0,
                                       data_source=service_name,
                                       severity=service_state,
                                       site_name=site,
                                       warning_threshold=0,
                                       critical_threshold=0,
                                       ip_address=host_ip)
            mongo_functions.mongo_db_insert(db, invent_service_dict,
                                            "inventory_services")
            invent_service_dict = {}
Exemple #2
0
def mongo_db_store(site, trap_result):
    trap_event_dict = {}
    db = mongo_functions.mongo_db_conn(site, "nocout_event_log")
    for row in trap_result:
        trap_event_dict = dict(traptime=row[11],
                               event_name=row[1],
                               trapoid=row[3],
                               discription=row[12],
                               agent_ip=row[7],
                               severity=row[9],
                               community=row[5],
                               enterprise=row[4],
                               uptime=row[10])
        print trap_event_dict
        mongo_functions.mongo_db_insert(db, trap_event_dict,
                                        "snmp_alarm_event")
def status_perf_data(site,hostlist):

	status_check_list = []
	status_service_dict = {}
	db = mongo_functions.mongo_db_conn(site,"nocout")
	for host in hostlist[0]:
		query = "GET hosts\nColumns: host_services\nFilter: host_name = %s\n" %(host)
		query_output = rrd_main.get_from_socket(site,query).strip()
		service_list = [service_name for service_name in query_output.split(',')]
		for service in service_list:
			if service.endswith('_status'):
				status_check_list.append(service)

		for service in status_check_list:
			query_string = "GET services\nColumns: service_state service_perf_data host_address\nFilter: " + \
			"service_description = %s\nFilter: host_name = %s\nOutputFormat: json\n" 	 	% (service,host)
			query_output = json.loads(rrd_main.get_from_socket(site,query_string).strip())
			perf_data_output = str(query_output[0][1])
			service_state = (query_output[0][0])
			host_ip = str(query_output[0][2])
                        current_time = int(time.time())
			if service_state == 0:
				service_state = "OK"
			elif service_state == 1:
				service_state = "WARNING"
			elif service_state == 2:
				service_state = "CRITICAL"
			elif service_state == 3:
				service_state = "UNKNOWN"
                	perf_data = rrd_migration.get_threshold(perf_data_output)
                	for ds in perf_data.iterkeys():
                        	cur =perf_data.get(ds).get('cur')
                        	war =perf_data.get(ds).get('war')
                        	crit =perf_data.get(ds).get('cric')
				status_service_dict = dict (sys_timestamp=current_time,check_timestamp=current_time,device_name=str(host),
                                                service_name=service,current_value=cur,min_value=0,max_value=0,avg_value=0,
                                                data_source=ds,severity=service_state,site_name=site,warning_threshold=war,
                                                critical_threshold=crit,ip_address=host_ip)
                        	mongo_functions.mongo_db_insert(db,status_service_dict,"status_services")

			query_output = json.loads(rrd_main.get_from_socket(site,query_string).strip())
		status_service_dict = {}
Exemple #4
0
#!/usr/bin/python
import sys, os
sys.path.append('/omd/sites/nms1')
import mongo_functions
#arg_list =str(sys.argv)

#with open("/omd/sites/nms1/nt1.log","a") as f1:
#	f1.write("nitin")

file_path = os.path.dirname(os.path.abspath(__file__))
path = [path for path in file_path.split('/')]

if len(path) <= 4 or 'sites' not in path:
    raise Exception, "Place the file in appropriate omd site"
else:
    site = path[path.index('sites') + 1]

notification_event_dict = {}
db = mongo_functions.mongo_db_conn(site, "nocout_event_log")
notification_event_dict = dict(host_address=sys.argv[1],
                               host_name=sys.argv[2],
                               host_state=sys.argv[3],
                               time=sys.argv[4])

mongo_functions.mongo_db_insert(db, notification_event_dict,
                                "notification_event")
#!/usr/bin/python
import sys,os
sys.path.append('/opt/omd/sites/nms1')
import mongo_functions
#arg_list =str(sys.argv)



#with open("/opt/omd/sites/nms1/nt1.log","a") as f1:
#	f1.write("nitin")


file_path = os.path.dirname(os.path.abspath(__file__))
path = [path for path in file_path.split('/')]	

if len(path) <= 4 or 'sites' not in path:
	raise Exception, "Place the file in appropriate omd site"
else:
	site = path[path.index('sites') + 1]

notification_event_dict = {}
db = mongo_functions.mongo_db_conn(site,"nocout_event_log")
notification_event_dict = dict(host_address=sys.argv[1],
		host_name=sys.argv[2],host_state=sys.argv[3],
		time=sys.argv[4])

mongo_functions.mongo_db_insert(db,notification_event_dict,"notification_event")
def extract_nagios_events_live():
	db = None
	file_path = os.path.dirname(os.path.abspath(__file__))
        path = [path for path in file_path.split('/')]

        if 'sites' not in path:
                raise Exception, "File is not in omd specific directory"
        else:
                site = path[path.index('sites')+1]
	
	utc_time = datetime(1970, 1,1)
        start_time = datetime.now() - timedelta(minutes=10)
        end_time = datetime.now()
        start_epoch = int((start_time - utc_time).total_seconds())
        end_epoch = int((end_time - utc_time).total_seconds())

        # sustracting 5.30 hours        
        start_epoch -= 19800
        end_epoch -= 19800
        host_event_dict ={}
        serv_event_dict={}
        db = mongo_functions.mongo_db_conn(site,"nocout_event_log")
	query = "GET log\nColumns: log_type log_time log_state_type log_state  host_name service_description options host_address\nFilter: log_time >= %s\nFilter: class = 0\nFilter: class = 1\nFilter: class = 2\nFilter: class = 3\nFilter: class = 4\nFilter: class = 6\nOr: 6\n" %(start_epoch) 
	output= rrd_main.get_from_socket(site, query)
	#print output
	for log_attr in output.split('\n'):
		log_split = [log_split for log_split in log_attr.split(';')]
		print log_split
		if log_split[0] == "CURRENT HOST STATE":
			host_ip = log_split[11]
                        #host_ip = log_split[10].split(':')[0]
                        #host_ip = host_ip.split('-')[1]
                        host_event_dict=dict(time=log_split[1],host_name=log_split[4],status=log_split[7],
                                                        state_type=log_split[2],discription=log_split[11],
                                                        ip_address=host_ip,event_type_name=log_split[0])
		
               		mongo_functions.mongo_db_insert(db,host_event_dict,"host_event")
		elif log_split[0] == "CURRENT SERVICE STATE":
			host_ip = log_split[12]

                        #host_ip = log_split[11].split(':')[0]
                        #host_ip = host_ip.split('-')[1]
                        serv_event_dict=dict(time=log_split[1],host_name=log_split[4],status=log_split[8],
                                                        state_type=log_split[2],discription=log_split[11],
                                                        ip_address=host_ip,event_type_name=log_split[0],event_name=log_split[5])
                        #print serv_event_dict
                        mongo_functions.mongo_db_insert(db,serv_event_dict,"serv_event")
	

		elif log_split[0] == "HOST ALERT":
			
			host_ip = log_split[11]
			#host_ip = log_split[10].split(':')[0]
			#host_ip = host_ip.split('-')[1]
			host_event_dict=dict(time=log_split[1],host_name=log_split[4],status=log_split[7],
                                                        state_type=log_split[2],discription=log_split[10],
                                                        ip_address=host_ip,event_type_name=log_split[0])
                	#print host_event_dict
               		mongo_functions.mongo_db_insert(db,host_event_dict,"host_event")
		elif log_split[0] == "HOST FLAPPING ALERT":
			host_ip = log_split[11]
			host_event_dict=dict(time=log_split[1],host_name=log_split[4],status=log_split[7],
                                                        state_type=None,discription=log_split[8],
                                                        ip_address=host_ip,event_type_name=log_split[0])
			mongo_functions.mongo_db_insert(db,host_event_dict,"host_event")
		elif log_split[0] == "SERVICE ALERT":
			
			host_ip = log_split[11]

			#host_ip = log_split[11].split(':')[0]
			#host_ip = host_ip.split('-')[1]
			serv_event_dict=dict(time=log_split[1],host_name=log_split[4],status=log_split[8],
                                                        state_type=log_split[2],discription=log_split[11],
                                                        ip_address=host_ip,event_type_name=log_split[0],event_name=log_split[5])
			#print serv_event_dict
               		mongo_functions.mongo_db_insert(db,serv_event_dict,"serv_event")

		elif log_split[0] == "SERVICE FLAPPING ALERT":
			serv_event_dict=dict(time=log_split[1],host_name=log_split[4],status=log_split[8],
                                                        state_type=None,discription=log_split[9],
                                                        ip_address=None,event_type_name=log_split[0],event_name=log_split[5])
			mongo_functions.mongo_db_insert(db,serv_event_dict,"serv_event")

		elif log_split[0] == "HOST NOTIFICATION":
			host_ip = log_split[11]
                        #host_ip = log_split[10].split(':')[0]
                        #host_ip = host_ip.split('-')[1]
                        host_event_dict=dict(time=log_split[1],host_name=log_split[4],status=log_split[7],
                                                        state_type=log_split[2],discription=log_split[10],
                                                        ip_address=host_ip,event_type_name=log_split[0])
                        #print host_event_dict
                        mongo_functions.mongo_db_insert(db,host_event_dict,"notification_event")

		elif log_split[0] == "SERVICE NOTIFICATION":

                        host_ip = log_split[12]

                        #host_ip = log_split[11].split(':')[0]
                        #host_ip = host_ip.split('-')[1]
                        serv_event_dict=dict(time=log_split[1],host_name=log_split[4],status=log_split[9],
                                                        state_type=log_split[2],discription=log_split[11],
                                                        ip_address=host_ip,event_type_name=log_split[0],event_name=log_split[5])
                        #print serv_event_dict
                        mongo_functions.mongo_db_insert(db,serv_event_dict,"notification_event")