http.ps1 - powershell script by ActiveXperts Software
http.ps1 read data from a web page and search for a pattern.
Use http.ps1 directly from ActiveXperts Network Monitor; in the Manager's 'Monitor' menu, select 'New Check (Script)' and select http.ps1. Configure the required parameter, or press 'Load a working sample'.
In ActiveXperts Network Monitor, Administrators can use three different scripting languages: Powershell, VBScript and SSH.
http.ps1 script code
#################################################################################
# ActiveXperts Network Monitor PowerShell script, © ActiveXperts Software B.V.
# For more information about ActiveXperts Network Monitor, visit the ActiveXperts
# Network Monitor web site at http://www.activexperts.com
#################################################################################
# Script
# Http.ps1
# Description:
# Read data from a web page and search for a predefined pattern.
# This function uses ActiveXperts Network Component.
# ActiveXperts Network Component is automatically licensed when ActiveXperts Network Monitor is purchased.
# For more information about ActiveXperts Network Component, see: www.activexperts.com/network-component
# Declare Parameters:
# 1) strURL (string) - URL of the web site, without http or https prefix
# 2) strPattern (string) - Text pattern to search for in the specified site
# Usage:
# .\Http.ps1 '<URL>' '<Text Pattern>'
# Sample:
# .\Http.ps1 'www.ActiveXperts.com' 'ActiveXperts'
#################################################################################
# -- Declare Parameters
param( [string]$strURL = '', [string]$strPattern = '' )
# -- Use _activexperts.ps1 with common functions
. 'C:\Program Files\ActiveXperts\Network Monitor\Scripts\Monitor (ps1)\_activexperts.ps1'
#################################################################################
# // --- Main script ---
#################################################################################
# -- Clear screen and clear error
cls
$Error.Clear()
# -- Validate parameters, return on parameter mismatch
if( $strURL -eq '' -or $strPattern -eq '' )
{
$res = 'UNCERTAIN: Parameter error - Usage: .\Http.ps1 "<URL>" "<Text Pattern>"'
echo $res
exit
}
# -- Create object
$objHttp = new-object -comobject AxNetwork.HttpEx
$strData = $objHttp.Get( $strURL )
if( $objHttp.LastError -ne 0 )
{
$res = 'ERROR: No response received from the remote server'
echo $res
exit
}
if( $strData -match $strPattern -eq 'true' )
{
$res = 'SUCCESS: Web site is available, text pattern found'
}
else
{
$res = 'UNCERTAIN: Web site is available, text pattern not found'
}
# -- Print script result
echo $res
exit
#################################################################################
# // --- Catch script exceptions ---
#################################################################################
trap [Exception]
{
$res = 'UNCERTAINs: ' + $_.Exception.Message
echo $res
exit
}
