Title: RE: [WhatsUp Forum] XML Schema & specs?

Here is what I do...  (this was annoying as the listgroup kept rejecting it since it was too big even though it was only 28k (limit is 50k) I striped some of the content to get it out.

I created a script which basically builds the files... I run the script manually weekly to
refresh the contents... I open the maps delete the contents import the xml file, arrange icons... next map... for
all the maps...

This works great for me since if the server melts there is nothing lost.

The end result looks like this:

WebServices(1)   xx sites
WebServices(2)   xx sites
WebServices(3)   xx sites
Location          x servers
Location          x servers
Location          x servers

Since we have several locations, 300 servers and a few hundred websites  I needed to automate this were possible.

Sorry its all in pearl and you will need the db structure to make it work but I thought it might be useful... if not at least in concept...

When I have time I am going to re-do it in .NET as a service and fully automate it, its not high on my list right now since I can tolerate the 15 mins it takes todo it weekly...

Good thing is that even though I am essentially deleting the maps every week since the names are consistent it seems to not disrupt the event logging.,

regards

Jason

Infrastructure Tools



<Regenerate MAPS script>
:: this will create the services file
MakeServices.pl

:: this will query our CMDB and extract sites by location
Wug-CreateMap.pl "1201 Wilson" > 1201Wilson.xml
Wug-CreateMap.pl "155 University" > 155UNI.xml
Wug-CreateMap.pl "900 Bay" > 900bay.xml
Wug-CreateMap.pl "Kingston" > Kingston.xml
Wug-CreateMap.pl "PRDC" > prdc.xml

:: this will generate our web sites again via the CMDB
Wug-CreateWebmap.pl


:: create services via database
use DBI;
use Win32::File;
$basefile = shift or $basefile='services.base';
my $dbh = DBI->connect('dbi:ODBC:PostgreSQL','user','pass');
if ([ -f $basefile ]){
 Win32::CopyFile($basefile,'services.ini', 1);
}
open SERVICES, ">>services.ini";
$dbh->{LongReadLen} = 2000;
my $sth = $dbh->prepare("select monitor_name,config_str from monitor_custom");
$sth->execute();
while ( ($name,$text) = $sth->fetchrow_array) {
 $mystring ="[$name]\n";
 $mystring .="$text\n";

 print SERVICES $mystring;
}


:: create server maps
use WugMap;
use XML::Parser::Expat;
use DBI;

$building = shift or die "Please input building";

$MAXCOLUMNS = 6;


srand( time() ^ ($$ << 15) );

local $dbh = DBI->connect('dbi:ODBC:PostgreSQL','user','pass');

$i = 0;
$dcounter = 0;
$mcounter = 0;
$icounter = 0;
$acounter = 0;
$h = 1;


$WUGMap = new WugMap;
$WUGDev = newDevice();

$row = 0;
$column = 0;


PopulateMap($WUGMap,"DefaultMap.xml");
$WUGMap->SetMapTitle($building);
$WUGMap->SetParentMapName("root.wug");

local $sth = $dbh->prepare( "select monitor_sid_type.sid,systems.name,monitor_type.Description,monitor_type.port from  systems,monitor_sid_type,monitor_type where monitor_sid_type.monitortypeid = monitor_type.monitortypeid and systems.sid = monitor_sid_type.sid and systems.monitor = TRUE and systems.building='$building' order by monitor_sid_type.sid");

$sth->execute;
while ( ($sid,$url,$monitorname,$port) = $sth->fetchrow_array) {
 $newmonitor = newDeviceMonitor();
 
 
 $newmonitor->DeviceMonitorSetName($monitorname,$newmonitor);
 $newmonitor->DeviceMonitorSetName($monitorname,$newmonitor);
 $newmonitor->DeviceMonitorSetTypeName(" ",$newmonitor);
 $newmonitor->DeviceMonitorSetArguments(" ",$newmonitor);
 $newmonitor->DeviceMonitorSetComment(" ",$newmonitor);
 $newmonitor->DeviceMonitorSetNumberOfDeviceLinks(" 0",$newmonitor);
 $newmonitor->DeviceMonitorSetIsMonitored('true',$newmonitor);
 
 if ($sid ne $oldsid){

  if ($column < $MAXCOLUMNS){
   $LocationX = 96*$column;
   $LocationY = 96*$row;
   $column++;
  }
  else {
   $column=0;
   $row++;
   $LocationX=0;
   $LocationY=96*$row;
  }

  $newdevice = newDevice();
  PopulateDevice($newdevice,"DefaultDev.xml");
  $newdevice->SetDeviceDisplayName($sid.'-'.$url,$newdevice);
  $newdevice->SetDeviceHostName($url,$newdevice);
  $newdevice->SetDeviceLocationX(sprintf("%.2f",$LocationX),$newdevice);
  $newdevice->SetDeviceLocationY(sprintf("%.2f",$LocationY),$newdevice);
 
  $number1 = rand(65535);
  $number2 = rand(65535);
  $newdevice->SetDeviceItemID("0x".(sprintf "%lx",$number1).(sprintf "%lx",$number2),$newdevice); 
  $WUGMap->AddDevice($sid,$newdevice);
 }
 $newdevice->DeviceAddDeviceMonitor('DevMon'.$h++,$newmonitor,$newdevice);
 $oldsid = $sid;
}

$WUGMap->printmap(\$$WUGMap);


sub PopulateMap {

 local $WUGObj = shift;
 local $DefaultMapFile = shift;

 local $parser = new XML::Parser::Expat;
 $parser->setHandlers( 'Start' => \&WUGStartTag,
                     'End'   => \&WUGEndTag,
                     'Char'  => \&WUGCharData);

 open(WUGMAP, $DefaultMapFile) or die "Couldn't open $DefaultMapFile\n";
 $parser->parse(*WUGMAP);
 close(WUGMAP);
}

sub PopulateDevice {
 
 local $WUGObj = shift;
 local $DefaultDeviceFile = shift;

 local $parser = new XML::Parser::Expat;
 $parser->setHandlers( 'Start' => \&WUGStartTag,
                     'End'   => \&WUGEndTag,
                     'Char'  => \&WUGCharData);

 open(WUGDEV, $DefaultDeviceFile) or die "Couldn't open $DefaultDeviceFile\n";
 $parser->parse(*WUGDEV);
 close(WUGDEV);

}

sub WUGStartTag
{
 my ($p, $el, %atts) = @_;

 if ($el eq 'Device'){$dcounter++; $current_device = "Device".$dcounter};
 if ($el eq 'DeviceMonitor'){$mcounter++; $current_monitor = "DeviceMonitor".$mcounter};
 if ($el eq 'MenuItem'){$icounter++; $current_item = "MenuItem".$icounter};
 if ($el eq 'Alert'){$acounter++; $current_item = "Alert".$acounter};


}

sub WUGEndTag
{
my ($p, $el) = @_;

 @test = $parser->context;
 shift @test;
 push @test, $el;
 
 local $count = @test;
 if (($count != 0) && ($parser->depth != 0)) {
  for($item=0;$item<@test;$item++){
   SWITCH: {
    if ($test[$item] eq 'Device') {$test[$item] = $current_device;last SWITCH; }
    if ($test[$item] eq 'DeviceMonitor'){$test[$item] = $current_monitor;last SWITCH; }
    if ($test[$item] eq 'MenuItem'){$test[$item] = $current_item;last SWITCH; }
    if ($test[$item] eq 'Alert'){$test[$item] = $current_item;last SWITCH; }
   }
  } 
 
  @myarray = ($parser->depth,@test,$el,$$WUGObj);
  $WUGObj->SetNLevelItem(@myarray);
 }

}

sub WUGCharData
{
 my ($p,$str) = @_;
 
 @test = $parser->context;
 shift @test;
 $count = @test;
 if ($count != 0) {
  for($item=0;$item<@test;$item++){
   SWITCH: {
    if ($test[$item] eq 'Device') {$test[$item] = $current_device;last SWITCH; }
    if ($test[$item] eq 'DeviceMonitor'){$test[$item] = $current_monitor;last SWITCH; }
    if ($test[$item] eq 'MenuItem'){$test[$item] = $current_item;last SWITCH;}
    if ($test[$item] eq 'Alert'){$test[$item] = $current_item;last SWITCH;}
   }
  }
   

  @myarray = ($parser->depth-1,@test,$parser->current_element,$str,$$WUGObj);
  $WUGObj->SetNLevelItem(@myarray);
 }
}



::CREATE web sites map

use WugMap;
use XML::Parser::Expat;
use DBI;
use Win32::File;
use FileHandle;

$MAXCOLUMNS = 6;
Win32::CopyFile('services.base','services.ini', 1);

# Used here, so we don't need no fancy pants file objects...
open SERVICES, ">>services.ini";


srand( time() ^ ($$ << 15) );

local $dbh = DBI->connect('dbi:ODBC:PostgreSQL','','');

$i = 0;
$dcounter = 0;
$mcounter = 0;
$icounter = 0;
$h = 1;
$bcount = 0;
$n = 0;
$entrust = 0;
$redirect = 0;
$ssl = 0;


$WUGMap = new WugMap;

$row = 0;
$column = 0;


PopulateMap($WUGMap,"DefaultMap.xml");
$WUGMap->SetMapTitle("Web Services");
$WUGMap->SetParentMapName("root.wug");

my $sth = $dbh->prepare("select distinct(service_names.name) from services,service_names where services.sri = service_names.sri and services.type='website' and services.state='Active' order by service_names.name");

$sth->execute();
my $website;
my $row;
$sth->bind_col(1,\$website);
while ($sth->fetch){

 $bcount++;
 
 (my($url,$port)) = split(':',$website);
 if (! defined($port)){$port='80'};
       
       
        if ($port eq "entrust"){
                    $entrust= "1";
                    $port=80;     
        }
       
        if ($port eq "redirect"){
             $redirect= "1";
             $port=80;
        }
        if ($port eq "ssl"){
             $ssl= "1";
             $port=443;
        }


 $newmonitor = newDeviceMonitor();
 
 $newmonitor->DeviceMonitorSetName('WM_'.$website,$newmonitor);
 $newmonitor->DeviceMonitorSetTypeName(" ",$newmonitor);
 $newmonitor->DeviceMonitorSetArguments(" ",$newmonitor);
 $newmonitor->DeviceMonitorSetComment(" ",$newmonitor);
 $newmonitor->DeviceMonitorSetNumberOfDeviceLinks(" 0",$newmonitor);
 $newmonitor->DeviceMonitorSetIsMonitored('true',$newmonitor);

 if ($column < $MAXCOLUMNS){
  $LocationX = 96*$column;
  $LocationY = 96*$row;
  $column++;
 }
 else {
  $column=0;
  $row++;
  $LocationX=0;
  $LocationY=96*$row;
 }

 $newdevice = newDevice();
 PopulateDevice($newdevice,"DefaultDev.xml");
 $newdevice->SetDeviceDisplayName($website,$newdevice);
 $newdevice->SetDeviceHostName($url,$newdevice);
 $newdevice->SetDeviceLocationX(sprintf("%.2f",$LocationX),$newdevice);
 $newdevice->SetDeviceLocationY(sprintf("%.2f",$LocationY),$newdevice);
 $newdevice->SetDeviceInfoLine1("http://$website/",$newdevice);
 $number1 = rand(65535);
 $number2 = rand(65535);
 $newdevice->SetDeviceItemID("0x".(sprintf "%lx",$number1).(sprintf "%lx",$number2),$newdevice); 
 $WUGMap->AddDevice($website,$newdevice);
 
 $newdevice->DeviceAddDeviceMonitor('DevMonWeb'.$h++,$newmonitor,$newdevice);

 $mystring ="[WM_$website]\nCLSID={72B6D231-D71E-11d2-8F74-0040054D7C1D}\nEOC=\n";
 
 if ( $redirect eq "1" ){
     $mystring .="SOC=GET HTTP://$url HTTP/1.1\\r\\n\\r\\n\r\nAccept: */*\r\nUser-Agent: Ipswitch_Whatsup/4.0\\r\\n\\r\\n\n"; 

 }
 else {
     $mystring .="SOC=GET /$url HTTP/1.0 \\r\\n\\r\\n\r\nAccept: */*\r\nUser-Agent: Ipswitch_Whatsup/4.0\\r\\n\\r\\n\n";

 }
 
 if ( $entrust eq "1"){
  $mystring .="EAC=~.*entrust\nSTQ=\n\TYPE=0\nPORT=$port\nTIMEOUT=60\nLines=2\n"; 
     }

    else {
  $mystring .="EAC=~.*</html>\nSTQ=\n\TYPE=0\nPORT=$port\nTIMEOUT=60\nLines=2\n";
      }

 if ( $redirect eq "1" ){
     $mystring .="Line000=Send=GET HTTP://$url \\r\\n\\r\\n\r\nAccept: */*\r\nUser-Agent: Ipswitch_Whatsup/4.0\\r\\n\\r\\n\n";

  }
 else {
 $mystring .="Line000=Send=GET /$url/ \\r\\n\\r\\n\r\nAccept: */*\r\nUser-Agent: Ipswitch_Whatsup/4.0\\r\\n\\r\\n\n";
  }

    if ( $entrust eq "1" ){
  $mystring .="Line001=Expect=~.*entrust\n";
  }

 elsif ( $ssl eq "1" ) {
 $mystring .="Line001=Expect=~.*\n";
 }

       
  else {
  $mystring .="Line001=Expect=~.\n";
 
  }


 
 $redirect = "0";
 $entrust = "0";
        $ssl = "0";
 
 print SERVICES $mystring;
 print $bcount;
 
 if ($bcount >= 60){
 
  # So that it can be passed to printmap function.
  $fh = new FileHandle ("> webmap$n.xml");
  $WUGMap->printmap(\$$WUGMap,$fh);
  undef($fh);
  $n++;
  $bcount = 0;
  #$WUGMap->destroy(); 
  undef($WUGMap);
  $WUGMap = new WugMap;
  $row = 0;
  $column = 0;
  PopulateMap($WUGMap,"DefaultMap.xml");
  $WUGMap->SetMapTitle("Web Services($n)");
  $WUGMap->SetParentMapName("root.wug");
 }
}


$fh = new FileHandle ("> webmap$n.xml");
$WUGMap->printmap(\$$WUGMap,$fh);
undef($fh);

close SERVICES;


sub PopulateMap {

 local $WUGObj = shift;
 local $DefaultMapFile = shift;

 local $parser = new XML::Parser::Expat;
 $parser->setHandlers( 'Start' => \&WUGStartTag,
                     'End'   => \&WUGEndTag,
                     'Char'  => \&WUGCharData);

 open(WUGMAP, $DefaultMapFile) or die "Couldn't open $DefaultMapFile\n";
 $parser->parse(*WUGMAP);
 close(WUGMAP);
}

sub PopulateDevice {
 
 local $WUGObj = shift;
 local $DefaultDeviceFile = shift;

 local $parser = new XML::Parser::Expat;
 $parser->setHandlers( 'Start' => \&WUGStartTag,
                     'End'   => \&WUGEndTag,
                     'Char'  => \&WUGCharData);

 open(WUGDEV, $DefaultDeviceFile) or die "Couldn't open $DefaultDeviceFile\n";
 $parser->parse(*WUGDEV);
 close(WUGDEV);

}

sub WUGStartTag
{
 my ($p, $el, %atts) = @_;

 if ($el eq 'Device'){$dcounter++; $current_device = "Device".$dcounter};
 if ($el eq 'DeviceMonitor'){$mcounter++; $current_monitor = "DeviceMonitor".$mcounter};
 if ($el eq 'MenuItem'){$icounter++; $current_item = "MenuItem".$icounter};


}

sub WUGEndTag
{
my ($p, $el) = @_;

 @test = $parser->context;
 shift @test;
 push @test, $el;
 
 local $count = @test;
 if (($count != 0) && ($parser->depth != 0)) {
  for($item=0;$item<@test;$item++){
   SWITCH: {
    if ($test[$item] eq 'Device') {$test[$item] = $current_device;last SWITCH; }
    if ($test[$item] eq 'DeviceMonitor'){$test[$item] = $current_monitor;last SWITCH; }
    if ($test[$item] eq 'MenuItem'){$test[$item] = $current_item;last SWITCH; }
   }
  }  
  @myarray = ($parser->depth,@test,$el,$$WUGObj);
  $WUGObj->SetNLevelItem(@myarray);
 }

}
sub WUGCharData
{
 my ($p,$str) = @_;
 
 @test = $parser->context;
 shift @test;
 $count = @test;
 if ($count != 0) {
  for($item=0;$item<@test;$item++){
   SWITCH: {
    if ($test[$item] eq 'Device') {$test[$item] = $current_device;last SWITCH; }
    if ($test[$item] eq 'DeviceMonitor'){$test[$item] = $current_monitor;last SWITCH; }
    if ($test[$item] eq 'MenuItem'){$test[$item] = $current_item;last SWITCH;}
   }
  }  
  @myarray = ($parser->depth-1,@test,$parser->current_element,$str,$$WUGObj);
  $WUGObj->SetNLevelItem(@myarray);
 }
}

Reply via email to