Contact Info

Crumbtrail

ActiveXperts.com » Administration » VBScript » Network Monitor » NNTP

Nntp.vbs - Monitoring NNTP news server availability using ActiveXperts Network Monitor

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 VBScript checks.

Most of the built-in checks have a VBScript equivalent, implemented as a Function in a VBScript (.vbs) file. Out-of-the-box, each VBScript function monitors the same items as the built-in check. Feel free to modify a function. The VBScript check can be customized by editing the VBScript function.

To add a new VBScript-based NNTP monitoring check, do the following:

To customize the above monitoring check, click on the 'Edit button' next to the 'File selection box'. Notepad will be launched. You can now make changes to the VBScript function(s).

Screenshot of a VBScript NNTP check

Nntp.vbs script source code

' ///////////////////////////////////////////////////////////////////////////////
' // ActiveXperts Network Monitor  - VBScript based checks
' //  ActiveXperts Software B.V.
' //
' // For more information about ActiveXperts Network Monitor and VBScript, please
' // visit the online ActiveXperts Network Monitor VBScript Guidelines at:
' //    https://www.activexperts.com/support/network-monitor/online/vbscript/
' // 
' ///////////////////////////////////////////////////////////////////////////////
'  

Option Explicit
Const  retvalUnknown = 1
Dim    SYSDATA, SYSEXPLANATION  ' Used by Network Monitor, don't change the names


' //////////////////////////////////////////////////////////////////////////////
' // To test a function outside Network Monitor (e.g. using CSCRIPT from the
' // command line), remove the comment character (') in the following 5 lines:
' Dim bResult
' bResult = CheckNntp( "nntp.activexperts-labs.com" )
' WScript.Echo "Return value: [" & bResult & "]"
' WScript.Echo "SYSDATA: [" & SYSDATA & "]"
' WScript.Echo "SYSEXPLANATION: [" & SYSEXPLANATION & "]"
' ////////////////////////////////////////////////////////////////////////////////////////


Function CheckNntp( strNntpServer )

' Description: 
'     Establish a telnet session to an NNTP new server and validate its response
'     NNTP servers always reply a '200' message when ready to establish a session
'     This function uses the Network Component, an ActiveXperts product.
'     Network Component is automatically licensed when ActiveXperts Network Monitor is purchased
'     For more information about Network Component, see: www.activexperts.com/network-component
' Parameters:
'     1) strNntpServer  - Host name or IP address of the mail server
' Usage:
'     CheckNntp( "" )
' Sample:
'     CheckNntp( "nntp.activexperts-labs.com" )

    CheckNntp     = retvalUnknown  ' Default return value
    SYSDATA             = ""             ' Not used by this function
    SYSEXPLANATION      = ""             ' Set initial value

    CheckNntp     = checkTelnet( strNntpServer, 119, "", "", "", "200" )

End Function








' //////////////////////////////////////////////////////////////////////////////
' //
' // Private Functions
' //   NOTE: Private functions are used by the above functions, and will not
' //         be called directly by the ActiveXperts Network Monitor Service.
' //         Private function names start with a lower case character and will
' //         not be listed in the Network Monitor's function browser.
' //
' //////////////////////////////////////////////////////////////////////////////


Function checkTelnet( strServer, numPort, strCommand1, strCommand2, strCommand3, strReceive )

    Dim objTcp, strAllResponses

    checkTelnet           = 1   ' Default return value
    SYSDATA               = ""  ' Not used by this function
    SYSEXPLANATION        = ""  ' Set initial value

    Set objTcp = CreateObject("ActiveXperts.Tcp")
    objTcp.Protocol       = 2 ' 1 means: raw, 2 means: telnet (see also Network Component manual)

    objTcp.Connect strServer, numPort
    If( objTcp.LastError <> 0 Or objTcp.ConnectionState <> 3 ) Then
        checkTelnet       = False
        SYSEXPLANATION    = "Unable to connect to [" & strServer & "]"
        objTcp.Disconnect ' can be called even when there's no connection
        Exit Function
    End If

    objTcp.Sleep( 2000 ) ' Allow some time

    tcprecv objTcp, strAllResponses 

    tcpsend objTcp, strCommand1
    tcprecv objTcp, strAllResponses

    tcpsend objTcp, strCommand2
    tcprecv objTcp, strAllResponses

    tcpsend objTcp, strCommand3
    tcprecv objTcp, strAllResponses

    If( InStr( UCase( strAllResponses ), UCase( strReceive )  ) <> 0 ) Then
      checkTelnet         = True
    Else
        checkTelnet       = False
    End If
    SYSEXPLANATION      = "Response=[" & strAllResponses & "]"

    objTcp.Disconnect    

End Function

Sub tcpsend( objTcp, strCommand )
    If( strCommand <> "" ) Then
      objTcp.SendString( strCommand )
    End If
End Sub


' //////////////////////////////////////////////////////////////////////////////

Sub tcprecv( objTcp, BYREF strAllResponses )
    Dim bHasData, strResponse 

    bHasData = objTcp.HasData

    While( bHasData )
      strResponse = objTcp.ReceiveString()
      bHasData = objTcp.HasData

      If( strAllResponses <> "" ) Then
        strAllResponses = strAllResponses & ".." ' .. to indicate a newline
      End If
      strAllResponses = strAllResponses & strResponse
    WEnd
End Sub