Source code

 

aon_offline.pl

use strict;
use LWP::UserAgent;
use XML::DOM;

#------ parameters ------

my $dbsecret = "dbsecret";
my $address = "1.2.3.4";
my $user = "user1";
my $pwd = "user1";
my $server = "http://127.0.0.1:7615/xmlmsg";

#------ body ------

my $from = "0";
my $dom_parser = new XML::DOM::Parser;
my $ua = LWP::UserAgent->new;

sub nodeValue {
  my($elm,$value) = @_;          
  return $elm->getElementsByTagName($value)->item(0)->getFirstChild->getNodeValue();
}

while (1) {
 my $out = '';
$out .=  <<EOF
<module secret="$dbsecret" name="ISL_ALWAYSON">
<user address="$address" username="$user" password="$pwd"/>
<list>
<cgi>
<prop name="search_form">true</prop>
<prop name="aonlist_count">100</prop>
<prop name="aonlist_from">$from</prop>
<prop name="search_desc"></prop>
<prop name="search_tag"></prop>
</cgi>
</list>
</module>
EOF
;

 my $req = HTTP::Request->new(POST => $server);
 $req->content_type('text/xml');
 $req->content($out);
 my $res = $ua->request($req);

 my $dom = $dom_parser->parse($res->content);
 my @comps =$dom->getElementsByTagName('computer');

 if (scalar(@comps) == 0) {
         exit;
 }

 $from += scalar(@comps);

 foreach my $comp (@comps) {
         my $status = nodeValue($comp, 'status');
         if ($status eq 'offline') {
                 print nodeValue($comp, 'address') . " ";
                 print nodeValue($comp, 'description') . "\n";
         }
 }

Was this article helpful?