ActiveXperts Network Monitor ships with a powerful set of pre-defined checks. Each individual check has a static number of configuration items. To monitor other items, or to combine monitoring items, you can make use of custom PowerShell checks.
Most of the built-in checks have a PowerShell equivalent, implemented as a PowerShell (.ps1) script file. Out-of-the-box, each PowerShell script monitors the same items as the built-in check. Feel free to modify the script.
To add a new PowerShell-based Database monitoring check, do the following:
- On the 'Monitor menu', open 'New Monitoring Check (Script)' and choose 'New PowerShell Check'. The 'PowerShell Check' dialog box appears;
- In the 'Script File' selection box, select 'Telnet.ps1';
- In the 'Script Parameters'group box enter the required parameters. You can also load a working sample first by clicking on the 'Click here to load a sample' link.
To customize the above monitoring check, click on the 'Edit button' next to the 'Script File' selection box. Notepad will be launched. You can now make changes to the PowerShell script.
Telnet.ps1 script source code
################################################################################# # ActiveXperts Network Monitor PowerShell script, (c) ActiveXperts Software B.V. # For more information about ActiveXperts Network Monitor, visit the ActiveXperts # Network Monitor web site at https://www.activexperts.com ################################################################################# # Script # Telnet.ps1 # Description: # Establish a telnet session to a POP3 mail server and validate its response # POP3 servers always reply a #+OK# message when ready to establish a session # This function uses the ActiveXperts Network Component, an ActiveXperts product. # 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 # Parameters: # 1) strServer - a telnet server to connect to # 2) numPort - the port to connect to # 3) strCommand1 - the first command to send to the telnet server # 4) strCommand2 - the second command to send to the telnet server # 4) strCommand3 - the third command to send to the telnet server # 5) strReceive - the string you should receive # Usage: # .\Telnet.ps1 '<Hostname | IP>' Port 'Command1' 'Command2' 'Command3' 'Receive string' # Sample: # .\Telnet.ps1 'telnet.activexperts-labs.com' 23 'library' 'mypasswd' '' 'Search your library' ################################################################################# # Parameters param ( [string]$strServer, [int]$numPort, [string]$strCommand1, [string]$strCommand2, [string]$strCommand3, [string]$strReceive ) # Check parameters input if ( ( [string]$strServer -eq "" ) -or ( [int]$numPort -eq "" ) -or ( [string]$strCommand1 -eq $null ) -or ( [string]$strCommand2 -eq $null ) -or ( [string]$strCommand3 -eq $null ) -or ( [string]$strReceive -eq "" ) ) { $res = "UNCERTAIN: Invalid number of parameters - Usage: .\Telnet.ps1 <Hostname | IP> <Port> <Command1> <Command2> <Command3> <Receive string>" echo $res exit } cls ################################################################################# # Functions ################################################################################# ################################################################################# function tcprecv { param ( [ref]$strAllRespons ) $strResponse = $null $bHasData = $null $bHasData = $objTcp.HasData() while ( $bHasData ) { $strResponse = $objTcp.ReceiveString() $bHasData = $objTcp.HasData() if ( $strAllRespons.Value -ne "" ) { #.. to indicate a newline $strAllRespons.Value = $strAllRespons.Value + "`n`r" } $strAllRespons.Value = $strAllRespons.Value + $strResponse } } ################################################################################# function tcpsend { param ( [ref]$strCommand ) if ( $strCommand.Value -ne "" ) { $objTcp.SendString( $strCommand.Value ) } } ################################################################################# # THE SCRIPT ITSELF ################################################################################# # Define variables $strAllResponses = "" # Create object $objTcp = new-object -comobject ActiveXperts.Tcp # 1 means: raw, 2 means: telnet (see also ActiveXperts Network Component manual) $objTcp.Protocol = 2 $objTcp.Connect( $strServer, $numPort ) if ( ($objTcp.LastError -ne 0 ) -or ( $objTcp.ConnectionState -ne 3 ) ) { return "UNCERTAIN: Unable to connect to [" + $strServer + "]" # can be called even when there's no connection $objTcp.Disconnect() exit } #write-host $objTcp.HasData() $objTcp.Sleep( 2000 ) # Allow some time tcprecv( [ref]$strAllResponses ) tcpsend( [ref]$strCommand1 ) tcprecv( [ref]$strAllResponses ) tcpsend( [ref]$strCommand2 ) tcprecv( [ref]$strAllResponses ) tcpsend( [ref]$strCommand3 ) tcprecv( [ref]$strAllResponses ) #write-host $strAllResponses # Checks values if ( ($strAllResponses -ne $null ) -or ( $strAllResponses -eq "" ) ) { if( ($strAllResponses.ToUpper()) -match ($strReceive.ToUpper()) -eq $true ) { $res = "SUCCESS: String <" + $strReceive + "> found DATA: 1" } else { $res = "ERROR: String <" + $strReceive + "> not found DATA: 0" } } else { $res = "UNCERTAIN: No data received" } #cls Write-Host $res $objTcp.Disconnect() exit