Curl Perform Methode

Romulus1689

Romulus1689

Foren As
Hi Leute,
Bin ziemlich neu was Perl angeht und würde mir ganz gerne ein Perl/Nagios-Skript schreiben um den Login auf einer Webseite zu überwachen.

Dazu benutze ich Curl, das ganze Skript funktioniert auch schon Problemlos.

Muss ich damit Nagios auch alles schön anzeigt, eine Zeile ausgeben in der eine Meldung steht.

Jedoch gibt mir die Methode "Perform" (z.B. $curl->perform;) den Gesamten Header der Webseite auf der Standardausgabe aus.

Weis einer von euch wie ich das wegbekomme?

Danke,
Gruß
Romulus1689
 
Ich würde ja LWP nutzen und nicht Curl, da es wesentlich besser performt. Aber unabhängig davon solltest du evtl. etwas mehr von deinem Skript zeigen, wenn dir hier jemand sagen soll, warum das ausgegeben wird, denn im Normalfall tut curl das nicht, es sei denn du nutzt das Programm 'curl' und nicht WWW::Curl.
 
Hi bitmuncher,
Hier ist dann mal das Skript, habe deswegen Curl genommen weil ich einfach nur das PHP-Skript von Scott Milliken umgeschrieben habe.

#!/usr/bin/perl

#use strict;
use warnings;
use WWW::Curl::Easy;

if (@ARGV < 3) {
print "Zu wenig Parameter!";
exit 3;
}
# OWA Login Check
# Written by Scott Milliken in PHP rewritten by Thomas Bruckmann in Perl
# Modified by Chris Funderburg for Exchange 2007 - May 21, 2010
# Permission granted to use under the GPL

my $hostaddress = $ARGV[0];
my $username = $ARGV[1];
my $password = $ARGV[2];

# You can just use the base URL for your default mailbox
# or you can add on to it to specify a group mailbox
# $mailboxURL = "https://email.mydomain.com" for default
# or for a shared NOC mailbox in the IT department...
my $mailboxURL = "https://$hostaddress/owa/";
my $authURL = "https://$hostaddress/owa/auth/logon.aspx?url=https://$hostaddress/owa/&reason=0";

# First go to the URL that a user would use so that you can get your session cookie set

my $curl = new WWW::Curl::Easy;

$curl->setopt(CURLOPT_URL, $mailboxURL);
$curl->setopt(CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)");
$curl->setopt(CURLOPT_FOLLOWLOCATION, '1');

# You need to define a cookie jar to store and retrieve
# the session cookies or this won't work
$curl->setopt(CURLOPT_COOKIEJAR, "cookies.txt");
$curl->setopt(CURLOPT_COOKIEFILE, "cookies.txt");
#url_setopt( $pg, CURLOPT_COOKIEFILE, "cookies.txt" );
$curl->setopt(CURLOPT_HEADER, '0');
#$curl->setopt(CURLOPT_RETURNTRANSFER, 0);

# Setting these to false is handy for checking multiple
# frontends that may share the same SSL cert, such as
# ones in a round robin DNS scheme, but you address
# them by the "real name" of the host
$curl->setopt(CURLOPT_SSL_VERIFYPEER, '0');
$curl->setopt(CURLOPT_SSL_VERIFYHOST, '0');

# Set this to true for debugging
$curl->setopt(CURLOPT_VERBOSE, '0');
my $response;
open (FILE, ">/dev/null");
$curl->setopt(CURLOPT_WRITEDATA,0);
$curl->setopt(CURLOPT_FILE,\*FILE);
my $err = $curl->errbuf;

$curl->perform();
my $info = $curl->getinfo(CURLINFO_HTTP_CODE);

print "\n########################\n";
if ($info ne "200") {
print "Critical - OWA ist nicht erreichbar!\n";
exit 2;
}

# Set the form data for posting the login information
my %postData = ();
$postData{'url'} = $mailboxURL;
$postData{'reason'} = '0';
$postData{'destination'} = $mailboxURL;
$postData{'flags'} = '0';
$postData{'username'} = $username;
$postData{'password'} = $password;
$postData{'SubmitCreds'} = 'Log On';

my $postText = "";

for my $key (keys %postData) {
$postText .= $key . "=" . $postData{$key} . "&";
}

$curl->setopt(CURLOPT_REFERER, $curl->getinfo(CURLINFO_EFFECTIVE_URL));
$curl->setopt(CURLOPT_URL, $authURL);
$curl->setopt(CURLOPT_POST, '1');
$curl->setopt(CURLOPT_POSTFIELDS, $postText);

$curl->perform;

# At this point you can either print the following
# status to show the result of logging in, or you
# can make another call to the web server for the
# individual frames, such as
# $mailboxURL . "/Inbox/?Cmd=contents" will give you
# the listing of inbox headers (if you call curl again)

$info = $curl->getinfo(CURLINFO_HTTP_CODE);

if ($info ne "200") {
print("Critical - OWA-Login mit User $username Fehlgeschlagen!\n");
exit 2;
}
print("OK - OWA-Login mit User $username erfolgreich!\n");
exit 0;
 
So wie ich das sehe gibt die perform()-Methode den Inhalt automatisch aus. Es wird ja im Prinzip nur die libcurl angesprochen und die gibt nunmal den erhaltenen Output des Servers auf STDOUT aus. Ich befürchte daher, dass du wohl doch LWP einsetzen musst.
 

Ähnliche Themen

Jaunty + Zend + Gdata + xampp

AVM Fritzbox Fon 7170 nach telnet-Verbindung

Email Duplikate in IMAP (Cyrus)

Squid nur zum maskieren der eigenen IP, nicht für Webserver auf port 80

Server-Monitoring mit RRDTool

Zurück
Oben