What do you mean when you say it is not hitting? Is there a specific error, or are you saying it simply isn't posting to your site?
Mike On Mon, Oct 30, 2017, 8:21 AM sourav voip <voipdev.sou...@gmail.com> wrote: > Hi All, > > I'm trying to hit request.post with condition using if-else as below... > I;m posting the full script here...as I've tried declaring post url details > tested with multiple places.. > > If condition for disk utiliztion is working perfect ,however request.post > is not hitting. > Please suggest any hint/clue as I'm a new learner in python. > > Regards, > Sourav > > ------------------------------------------------------------ > ------------------------- > #!/usr/bin/python > import re,sys,commands > import requests > # Set the request parameters > url = 'https://devxxxx.service-now.com/api/now/table/incident' > > # Eg. User name="admin", Password="admin" for this code sample. > user = 'admin' > pwd = 'xxxx' > > # Set proper headers > headers = {"Content-Type":"application/json","Accept":"application/json"} > > > ################# > #Set variables > command = "df /" > critical = 50.0 > warning = 40.0 > ################# > > #build regex > dfPattern = re.compile('[0-9]+') > > #get disk utilization > diskUtil = commands.getstatusoutput(command) > > #split out the util % > diskUtil = diskUtil[1].split()[11] > > #look for a match. If no match exit and return an > #UNKNOWN (3) state to Nagios > > matchobj = dfPattern.match(diskUtil) > if (matchobj): > diskUtil = eval(matchobj.group(0)) > else: > print "STATE UNKNOWN" > sys.exit(3) > > #Determine state to pass to Nagios > #CRITICAL = 2 > #WARNING = 1 > #OK = 0 > if diskUtil >= critical: > url = 'https://devxxxx.service-now.com/api/now/table/incident' > user = 'admin' > pwd = 'xxxx' > headers = {"Content-Type":"application/json","Accept":"application/ > json"} > requests.post(url, auth=(user, pwd), headers=headers > ,data="{\"assignment_group\":\Hardware\",\"short_description\":\"Threshold > critical\"}") > print "FREE SPACE CRITICAL: '/' is %.2f%% full" % (float(diskUtil)) > sys.exit(2) > elif diskUtil >= warning: > requests.post(url, auth=(user, pwd), headers=headers > ,data="{\"assignment_group\":\Hardware\",\"short_description\":\"Threshold > Warning\"}") > print "FREE SPACE WARNING: '/' is %.2f%% full" % (float(diskUtil)) > sys.exit(1) > else: > print "FREE SPACE OK: '/' is %.2f%% full" % (float(diskUtil)) > sys.exit(0) > > > On Mon, Oct 30, 2017 at 4:04 PM, sourav voip <voipdev.sou...@gmail.com> > wrote: > > > Hi All, > > > > I'm trying to hit request.post with condition using if-else as below... > > I;m posting the full script here...as I've tried declaring post url > > details tested with multiple places. > > > > > > > > > > > _______________________________________________ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- https://mail.python.org/mailman/listinfo/python-list