Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

cURL scripts to monitor an API

by jim.fazzone.5i (Initiate)
on Aug 19, 2013 at 23:37 UTC ( [id://1050104]=perlquestion: print w/replies, xml ) Need Help??

jim.fazzone.5i has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!

My Perl-fu is severely lacking, but I was hoping I could turn to all of you to help me with some monitoring I'm trying to get working on a Nagios box. I know how the cURL scripts should look, but I'm having trouble with getting PERL to run these as a monitoring job. Essentially the flow goes like this:

1) POST command calls an SSO service with a user/pass

2) That SSO token then gets inserted into the header of the request of the subsequent URL

3) The API spits back data

Simple enough, right?

My cURL scripts run like so:

curl -v -X POST -d "username=testusergoeshere@gmail.com&password=somec +oolpassword" https://xxxx.xxxxx.com/PathtotheSSOTool (out spits the token) curl -v -X GET --header "TOKEN: xxxxxxxxxxxxxxxxxxxxxxxxxxxx.*xxxxxxxx +xxxxxxxxxxxxx..*" http://url.of.the/api/call

Then, I'd like to be able to capture whatever the browser would spit back into a .log file. If it has stuff in it, great! If it returns with ERROR, we want it to alarm.

Easy enough, but I'm totally stuck on how to get started here. Any thoughts?

Replies are listed 'Best First'.
Re: cURL scripts to monitor an API
by Corion (Patriarch) on Aug 20, 2013 at 05:21 UTC

    Depending on how close you want to stay to cURL, look either at LWP::UserAgent or at cURL.

    Using LWP::UserAgent together with HTTP::Request::Common should be fairly easy to send the messages:

    my $ua= LWP::UserAgent->new(); my $res= $ua->post( $url, { username => 'testusergoeshere@gmail.com', +password => 'somecoolpassword' }); $res->dump;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1050104]
Approved by Jim
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-19 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found