How Can We Help?
Categories
< All Topics
Print

How do I write my own custom server health monitor?

You can write a custom health monitor specific to your needs using PERL.

The #Monitor-Name: command is the name used for the Perl Script stored on the ADC. If you do not include this line, then your script will not be found!

The following are mandatory:

  • #Monitor-Name
  • use strict;
  • use warning;

The Perl scripts are run in a CHROOTED environment. They often call another application such as WGET or CURL. Sometimes these need to be updated for a specific features, such as SNI.

Dynamic Values

  • my $host = $_[0]; – This uses the “Address” from IP Services–Real Server section
  • my $port = $_[1]; – This uses the “Port” from IP Services–Real Server section
  • my $content = $_[2]; – This uses the “Required Content” value from the Library–Real Server Monitoring section
  • my $notes = $_[3]; – This uses the “Notes” column in Real Server section of IP Services
  • my $page = $_[4]; – This uses the “Page Location” values from Library–Real Server Monitor section
  • my $user = $_[5]; – This uses the “User” value from the Library–Real Server Monitor section
  • my $password = $_[6]; – This uses the “Password” value from the Library–Real Server Monitor section

See below images that show where the Dynamic Values are obtained from:

Custom Health Checks have two outcomes:

  • Successful
    Return Value 1
    Print a success message to Syslog
    Mark the Real Server Online (provided IN COUNT match)
  • Unsuccessful
    Return Value 2
    Print a message saying Unsuccessful to Syslog
    Mark the Real Server Offline (provided OUT Count match)

An Example Custom Monitor

#Monitor-Name: Edgenexus-Agfa-Status-Health-Check
use strict;
use warnings;
########################################################################################################
# Edgenexus custom health checking Copyright Edgenexus 2023
########################################################################################################
#
#
# This is a Perl script for Edgenexus customer health checking
# The monitor name as above is displayed in the dropdown of Available health checks
# There are 3 value passed to this script
#
# I am using:
# _[0] IP address of the server to be health checked
# _[2] Required content - 200OK
# _[4] Page - Location and Port to use
# my $host = $_[0]; - This uses the “Address” from IP Services--Real Server section
# my $port = $_[1]; - This uses the “Port” from IP Services--Real Server section
# my $content = $_[2]; - This uses the “Required Content” value from the Library--Real Server Monitoring section
# my $notes = $_[3]; - This uses the “Notes” column in Real Server section of IP Services
# my $page = $_[4]; - This uses the “Page Location” values from Library--Real Server Monitor section
# my $user = $_[5]; - This uses the “User” value from the Library--Real Server Monitor section
# my $password = $_[6]; - This uses the “Password” value from the Library--Real Server Monitor section
#
# The script will return the following values
# 1 is the test is successful
# 2 if the test is unsuccessful
#
sub monitor
{
  my $host = $_[0]; ### Host IP or name
  my $content = $_[2]; ### Required Response
  my $cvar = $_[4]; ### Path to be checked (Path, Port, prefix)
  my ($page, $port, $prefix) = split(/,\s*/, $cvar);
  $host = "$host:$port";
  my @lines = `/usr/bin/wget -q -S --tries=1 --timeout=1 --no-check-certificate --output-document=- $prefix://$host$page 2>&1`;
  if (join("",@lines))
  {
    print "$prefix://$host$page looking for - $content - Healhcheck check successful\n";
    return(1);
  }
else
  {
    print "$prefix://$host$page looking for - $content - Healhcheck check failed.\n";
    return(2)
  }
}
monitor(@ARGV);

Custom Monitoring – Use of global variables is not possible. Use local variables only – variables defined inside functions

Use of RegEx – All regular expressions must use a Perl-compatible statement syntax.

Scroll to Top
WordPress Appliance - Powered by TurnKey Linux