Forum Discussion

Christian_Laute's avatar
Christian_Laute
Icon for Nimbostratus rankNimbostratus
May 02, 2017

Using variables in external Perl monitor

Gents, I currently use a external monitor to check the JSON output of some webservices. Now I try to make it a little bit more flexible.

For example I want to try to replace the string "UP" at if($status eq "UP") to if($status eq $statusmsg) but not sure how to do this.

Current script:

!/usr/bin/env perl
use LWP::Simple;
use JSON;

$URI = $ARGV[2];
$HOSTNAME = $ARGV[0];
$HOSTNAME =~ s/::ffff://;
$PORT=$ARGV[1];

$contents = get("http://$HOSTNAME:$PORT$URI");
$json = decode_json($contents);
$status = $json->{'status'};
if($status eq "UP") {
    print $status;
}

Typing in the variable like below did not help. Also hard to find any documentations about it....

Maybe anyone of you can help me out? Many thanks