Contact Info

Crumbtrail

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

Tftp.vbs - Monitoring TFTP 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 TFTP 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 TFTP check

Tftp.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 = CheckTftp( "10.1.1.100", "/music/song001.mp3" )
' WScript.Echo "Return value: [" & bResult & "]"
' WScript.Echo "SYSDATA: [" & SYSDATA & "]"
' WScript.Echo "SYSEXPLANATION: [" & SYSEXPLANATION & "]"
' ////////////////////////////////////////////////////////////////////////////////////////


Function CheckTftp( strHost, strFile )

' Description:
'     Check for file existence on a TFTP host
'     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) strHost - Host name or IP address of the TFTP host
'     2) strFile - The file to check 
' Usage:
'     CheckTftp( "", "" )
' Sample:
'     CheckTftp( "10.1.1.100", "/music/song001.mp3" )

    Dim objTftpServer, objFileSystem, strTempFile

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

    Set objTftpServer = CreateObject("ActiveXperts.TftpServer")

    ' Use binary transfer
    objTftpServer.BinaryTransfer = True

    ' Use default port 69
    objTftpServer.HostPort       = 69

    ' Create a temp file to download file to
    Set objFileSystem = CreateObject("Scripting.FileSystemObject") 
    strTempFile = objFileSystem.GetSpecialFolder(2) & "\" & objFileSystem.GetTempName

    ' Get file
    objTftpServer.Get strHost, strFile, strTempFile
    If( objTftpServer.LastError = 0 ) Then
       CheckTftp       = True
       SYSEXPLANATION  = "File [" & strFile & "] found on TFTP host [" & strHost & "]; size=[" & objTftpServer.BytesReceived & " bytes]"
    Else
       CheckTftp       = False
       SYSEXPLANATION  = "File [" & strFile & "] not found on TFTP host; result=[" & objTftpServer.LastError & ": " & objTftpServer.GetErrorDescription( objTftpServer.LastError ) & "]"
    End If

    If( objFileSystem.FileExists( strTempFile ) ) Then
       objFileSystem.DeleteFile strTempFile
    End If 

End Function