lunes, 15 de diciembre de 2014

Where Medevac is Failing ... you can use Perl

Hi to everyone!!!

Citrix Medevac is a fantastic tool but does not work fine with xenapp 6.5.
If you need check your XML Servicers healthy, you can use Perl to launch a script, it is the same used by Netscaler to monitoring the XML service, or very similar.

This script is tested with Perl Strawberry 5.x and works fine.

Only you need publish a app in the XML servers and you must launch the script to the specific servers and asking by this app. You can use a Batch file to run the script to the all brokers servers.
If you have xenapp 5, you can use this script to test all xenapp servers in the farm.

Ok, it is true. you can use third parties monitoring to acomplish this task, but come on....a lot off times this agents are not working. or maybe, if some 'monkey' of monitoring department call you at 3 A.M. you need a simple script to test really the healthy of all entire citrix farm.


If you have a txt file with all XML servers, you can create a batch script like thius to launch the perl script:

FOR /F "eol=; tokens=1 delims=; " %%i in (xmlbroker.txt) do (
CitrixTestXMLService_v02.pl %%i 8080 "notepad-xml-service" %historic_file% %Log_file%
)


And this is the Perl Script:

#!/usr/bin/perl -w
# This script can be run at the command line on a laptop or server
# to verify functionality of the Citrix XML Service
# To invoke this script type:
# perl test_xml_service.pl <ipaddress> <xml_port> [ appname ] #
#!/usr/local/bin/perl

use strict;
use IO::Socket;

my $now_string = localtime;

if ($#ARGV < 1) {
print "\nUsage: perl test_xml_service.pl <ipaddress> <xml_port> [app name]\n";
exit 0;
}
my $ip_address = $ARGV[0];
my $xml_port = $ARGV[1];
my $hostname = `hostname`;
my $app = $ARGV[2] || "notepad";

chop($hostname);

open(LOGFILE, ">>", $ARGV[3]);
open(STDERR, ">>", $ARGV[4]);

my $xml_request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
"<!DOCTYPE NFuseProtocol SYSTEM \"NFuse.dtd\">\n" .
"<NFuseProtocol version=\"4.1\">\n" .
"<RequestAddress>\n" .
"<Flags>no-load-bias</Flags>" .
"<Name>\n" .
"<AppName>$app</AppName>\n" .
"</Name>\n" .
"</RequestAddress>\n" .
"</NFuseProtocol>\n";
my $content_length = length($xml_request);
my $header = "POST /scripts/wpnbr.dll HTTP/1.1\r\n" .
"Content-Type: text/xml\r\n" .
"Content-Length: $content_length\r\n" .
"Host: $hostname\r\n" .
"\r\n";
print "Target Server: $ip_address:$xml_port\n";
print "Header:\n";
print $header;
print "XML Request:\n";
print $xml_request . "\n";
print "-------\n\n";
my $socket1 = IO::Socket::INET->new(PeerAddr => $ip_address,PeerPort => $xml_port,
Proto => 'tcp')  || die $ARGV[0] . ":" . $ARGV[1] . " -> $@ " . $now_string . " ;\n";
print $socket1 $header . $xml_request;
my @output;
while (<$socket1>) {
if (m/\<\/NFuseProtocol\>/) {
close($socket1);
last;
}
else {
push @output, $_;
}
}
push @output, $_;
print @output;
my $output;
foreach $output (@output)
{
if ($output =~ /tickettag/i) {
print LOGFILE $ARGV[0] . " " . $ARGV[1] . " " . " -> exit 0 - " . $now_string . "\n"; 
exit 0;
}
}
@output = "null";
print STDERR $ARGV[0] . ":" . $ARGV[1] . " -> exit 1 " . $now_string . " ;\n"; 
print LOGFILE $ARGV[0] . ":" . $ARGV[1] . " -> exit 1 - " . $now_string . " ;\n"; 
exit 1;

No hay comentarios:

Publicar un comentario