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 getHostIP(host, hostid, username, token):
    url = "https://" + host + "/rest/config/host/"+hostid
    print url
    dataFile = Ops.opsgetsend_rawjson(url=url, user=username, key=token)
    dataFile = json.loads(dataFile)
    print dataFile["object"]["ip"]
    return(dataFile["object"]["ip"])
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