Re: [Tutor] request.post in If condition

2017-10-31 Thread Mike Miller
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  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://dev.service-now.com/api/now/table/incident'
>
> # Eg. User name="admin", Password="admin" for this code sample.
> user = 'admin'
> pwd = ''
>
> # 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://dev.service-now.com/api/now/table/incident'
> user = 'admin'
> pwd = ''
> 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 
> 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  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Help with python 2.7

2017-10-30 Thread Mike Miller
This is a mailing list, so the best way to get help is to send a request
with code examples and most importantly what you have already tried. That
being said, there are some smart people on here, much more experienced than
I am on Python so I would say you can get help with any problem you may
have.

I have taken the MIT course you are talking about and it is quite
challenging (perhaps a little more than it should be) and my oldest son at
one point took the Microsoft MVA course on the subject of python and he
said it was very good (surprisingly enough)..he is a Java programmer
primarily and said that for someone with even average skill and ability,
the MS course is actually great and easy to follow on. Good luck, and
welcome.

Mike

On Mon, Oct 30, 2017, 7:24 PM Alchemy  wrote:

> Hello,
>
> I am in the midst of a career change from renovations to computers.
> I’m used to working conceptually and understand coding is that.
> I am taking an online opencourseare classfrom MIT “Introduction to
> computer science and programming”.
> The class uses python 2.7, has video lectures and homework assignments
> that are coding exercises.
> Python seems like the root to everything in the computers possabilities
> and I want to internalize it.
> I’m stuck on the homework ,butmore importantly stuck on the concepts
> behind the homework.
>
> Can your orginazation help?
>
> gratefully,
>
> Ian
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor