def read_data(site_name, start_time, end_time):
    db = None
    port = None
    docs = []
    start_time = datetime(2014, 6, 4, 12, 35)
    end_time = datetime(2014, 6, 4, 12, 40)
    #start_time = datetime(2014, 6, 5, 13, 20)
    #end_time = datetime(2014, 6, 5, 13, 30)
    print "-- start_time, end_time --"
    print start_time, end_time
    port = db_port(site_name=site_name)
    if port:
        db = mongo_conn(
            host='localhost',
            port=int(port),
            db_name='nocout'
        )
    if db:
        cur = db.device_perf.find({
            "local_timestamp": {"$gt": start_time, "$lt": end_time}
        })
        for doc in cur:
            docs.append(doc)
     
    return docs
def extract_nagios_events_live(mongo_host, mongo_db, mongo_port):
	db = None
	perf_data  = {}
        file_path = os.path.dirname(os.path.abspath(__file__))
        path = [path for path in file_path.split('/')]
	war = None
	crit = None
	cur = None
        if 'sites' not in path:
                raise Exception, "File is not in omd specific directory"
        else:
                site = path[path.index('sites')+1]
	
        db = rrd_migration.mongo_conn(
		host=mongo_host,
		port=mongo_port,
		db_name=mongo_db
	)
	utc_time = datetime(1970, 1,1,5,30)
	#start_epoch = get_latest_event_entry(db_type = 'mongodb',db=db)
	#if start_epoch == None:
	start_time = datetime.now() - timedelta(minutes=1)
	start_epoch = int((start_time - utc_time).total_seconds())
        end_time = datetime.now()
        end_epoch = int((end_time - utc_time).total_seconds())
	
        # sustracting 5.30 hours        
        host_event_dict ={}
        serv_event_dict={}
	
	query = "GET log\nColumns: log_type log_time log_state_type log_state  host_name service_description "\
		"options host_address current_service_perf_data\nFilter: log_time > %s\nFilter: class = 0\nFilter: class = 1\n"\
		"Filter: class = 2\nFilter: class = 3\nFilter: class = 4\nFilter: class = 6\nOr: 6\n" %(start_epoch) 
	output= rrd_main.get_from_socket(site, query)

	for log_attr in output.split('\n'):
		log_split = [log_split for log_split in log_attr.split(';')]
		if log_split[0] == "CURRENT SERVICE STATE":
			service_perf_data_live_query(db,site,log_split)
		elif log_split[0] == "SERVICE ALERT" or log_split[0] == "INITIAL SERVICE STATE":
			service_perf_data_live_query(db,site,log_split)
		elif log_split[0] == "SERVICE FLAPPING ALERT":
			service_perf_data_live_query(db,site,log_split)

	query = "GET log\nColumns: log_type log_time log_state_type log_state  host_name service_description "\
		"options host_address current_host_perf_data\nFilter: log_time > %s\nFilter: class = 0\n"\
		"Filter: 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)

	for log_attr in output.split('\n'):
		log_split = [log_split for log_split in log_attr.split(';')]
		if log_split[0] == "CURRENT HOST STATE":
			network_perf_data_live_query(db,site,log_split)	
		elif log_split[0] == "HOST ALERT" or log_split[0] == "INITIAL HOST STATE":
			network_perf_data_live_query(db,site,log_split)	
		elif log_split[0] == "HOST FLAPPING ALERT":
			network_perf_data_live_query(db,site,log_split)	
Esempio n. 3
0
def read_data(start_time, end_time, **kwargs):
    db = None
    port = None
    docs = []
    db = mongo_conn(host=kwargs.get('configs').get('host'),
                    port=int(kwargs.get('configs').get('port')),
                    db_name=kwargs.get('configs').get('nosql_db'))
    if db:
        if start_time is None:
            cur = db.nocout_service_event_log.find()
        else:
            cur = db.nocout_service_event_log.find(
                {"check_timestamp": {
                    "$gt": start_time,
                    "$lt": end_time
                }})
        for doc in cur:
            docs.append(doc)
    return docs
Esempio n. 4
0
def read_data(start_time, end_time, **kwargs):

    db = None
    port = None
    docs = []
    #end_time = datetime(2014, 6, 26, 18, 30)
    #start_time = end_time - timedelta(minutes=10)
    docs = []
    db = mongo_conn(host=kwargs.get('configs').get('host'),
                    port=int(kwargs.get('configs').get('port')),
                    db_name=kwargs.get('configs').get('nosql_db'))
    if db:
        cur = db.nocout_inventory_service_perf_data.find(
            {"check_timestamp": {
                "$gt": start_time,
                "$lt": end_time
            }})
        for doc in cur:
            docs.append(doc)

    return docs
def read_data(site_name, start_time, end_time):
    db = None
    port = None
    docs = []
    start_time = datetime(2014, 6, 4, 12, 35)
    end_time = datetime(2014, 6, 4, 12, 40)
    #start_time = datetime(2014, 6, 5, 13, 20)
    #end_time = datetime(2014, 6, 5, 13, 30)
    print "-- start_time, end_time --"
    print start_time, end_time
    port = db_port(site_name=site_name)
    if port:
        db = mongo_conn(host='localhost', port=int(port), db_name='nocout')
    if db:
        cur = db.device_perf.find(
            {"local_timestamp": {
                "$gt": start_time,
                "$lt": end_time
            }})
        for doc in cur:
            docs.append(doc)

    return docs
Esempio n. 6
0
def read_data(start_time, end_time, **kwargs):

    db = None
    port = None
    docs = []
    #end_time = datetime(2014, 6, 26, 18, 30)
    #start_time = end_time - timedelta(minutes=10)
    
    db = mongo_conn(
        host=kwargs.get('configs').get('host'),
        port=int(kwargs.get('configs').get('port')),
        db_name=kwargs.get('configs').get('nosql_db')
    )
    if db:
    	if start_time is None:
            cur = db.network_perf.find()
	else:
        	cur = db.network_perf.find({
            	"check_time": {"$gt": start_time, "$lt": end_time}
        	})
        for doc in cur:
            docs.append(doc)
     
    return docs