def request_rest_event_splunk(token, username, host, params, service_state, host_group, raw): if params == "": if not host_group or not service_state: print "you don't have startTime and host_group information for request" sys.exit() else: for each in ["ok", "warning", "critical", "unknown"]: if service_state == each: params += "service_state=" + service_state + "&" else: continue params += "host_group=" + str(host_group) + "&" else: pass params += "cols=state&cols=hostname&cols=time&cols=output" url = "https://" + host + "/rest/event?" + params + "&format_datetime=1" print "request url is", url if raw == 0: # get data from API as dictionary format dataFile = Ops.opsgetsend(url, user=username, key=token) elif raw == 1: # get data from API as json raw format dataFile = Ops.opsgetsend_rawjson(url, user=username, key=token) #print dataFile return dataFile
def request_rest_status(token, username, params, state, servicetype, host, hostgroupid): reqservicetype = "" if params == "": if servicetype == 0: reqservicetype = "status/service" if not state and not hostgroupid: print "you don't have state and hostgroupid information for request" sys.exit() else: params = "state="+str(state)+"&"+"hostgroupid="+str(hostgroupid) elif servicetype == 1: reqservicetype = "status/host" if not state and not hostgroupid: print "you don't have state and hostgroupid information for request" sys.exit() else: params = "state="+str(state)+"&"+"hostgroupid="+str(hostgroupid) elif servicetype == 2: reqservicetype = "status/hostgroup" if not state and not hostgroupid: print "you don't have state and hostgroupid information for request" sys.exit() else: params = "state="+str(state)+"&"+"hostgroupid="+str(hostgroupid) elif servicetype == 3: reqservicetype = "status/viewport" if not state and not hostgroupid: print "you don't have state and hostgroupid information for request" sys.exit() else: params = "state="+str(state)+"&"+"hostgroupid="+str(hostgroupid) elif servicetype == 4: reqservicetype = "status/performancemetric" if not state and not hostgroupid: print "you don't have state and hostgroupid information for request" sys.exit() else: params = "state="+str(state)+"&"+"hostgroupid="+str(hostgroupid) else: print "error params" sys.exit() else: pass url = "https://"+host+"/rest/"+reqservicetype+"?"+params+"&format_datetime=1" print "request url is", url dataFile = Ops.opsgetsend(url, user=username, key=token) #print dataFile if servicetype == 0: interpret_rest_status_service(dataFile) elif servicetype == 1: interpret_rest_status_host(dataFile) elif servicetype == 2: interpret_rest_status_hostgroup(dataFile) else: sys.exit("Service Type is not support by program")
def request_rest_event_splunk_all(token, username, host, params, raw): params += "cols=state&cols=hostname&cols=time&cols=output" url = "https://" + host + "/rest/event?" + params + "&format_datetime=1" print "request url is", url if raw == 0: # get data from API as dictionary format dataFile = Ops.opsgetsend(url, user=username, key=token) elif raw == 1: # get data from API as json raw format dataFile = Ops.opsgetsend_rawjson(url, user=username, key=token) #print dataFile return dataFile
def request_rest_event_splunk_host_state(token, username, host, params, host_state, state_type, raw): if not host_state or not state_type: print "you have to input host_state in function request_rest_event_splunk_host_state" sys.exit() else: params += "host_state=" + host_state + "&"+"state_type="+state_type+"&" params += "cols=state&cols=hostname&cols=time&cols=output" url = "https://" + host + "/rest/event?" + params + "&format_datetime=1" print "request url is", url if raw == 0: # get data from API as dictionary format dataFile = Ops.opsgetsend(url, user=username, key=token) elif raw == 1: # get data from API as json raw format dataFile = Ops.opsgetsend_rawjson(url, user=username, key=token) #print dataFile return dataFile