The script functions
Previous  Top  Next


A number of built in functions are available from the Fields object. More functions will be added to future releases to help improve the functionality of the scripting engine.

To use a built in function, simply access the function name prefixed with the Fields object. Pass any parameters needed and the result will be returned.


Built-in functions of the "Fields" object

Fields.IsValidIPAddress(IPAddress as string) as Boolean

Function: Checks the string passed to it and returns true if the string has a valid IP address format.
Input parameters: IPAddress as string
Return value: Boolean (true/false)

Example usage:
If Fields.IsValidIPAddress(Fields.VarPeerAddress) = True then
   Fields.VarCustom01 = Fields.VarPeerAddress
End if


Fields.ConvertIPtoHex(IPAddress As String) As String

Function: Converts an IP address to 8 byte hex format.
Input parameters: IPAddress as string
Return value: 8 byte hex value

Example usage:
If Fields.IsValidIPAddress(Fields.VarPeerAddress) = True then
   Fields.VarCustom01 = Fields.ConvertIPToHex(Fields.VarPeerAddress)
End if


Fields.GetDailyStatistics() As String

Function: Returns the daily statistics page as a CRLF delimited string.
Input parameters: None
Return value: String

Example usage:
MyStats = Fields.GetDailyStatistics()

The resulting string can then be written to a file or e-mailed etc.


Fields.ConvertPriorityToText(PriorityValue)

Function: Converts a message priority value to a text representation of the facility.level.
Input parameters: Priority value
Range: 0 to 191
Return value: Facility.Level as text string
Example: A value of 191 returns "Local7.Debug"
Example usage:

Filename = "C:\Program files\Syslogd\Logs\TestLog.txt"
' Use the date and time from the current message
With Fields
     MsgDate = .VarDate & " " & .VarTime 
     MsgText = "This is a test message from the scripting action"
     Data = MsgDate & vbtab & .ConvertPriorityToText(.VarPriority) & vbtab & _
            .VarPeerAddress & vbtab & MsgText
     Call .ActionLogToFile(Filename, Data)
End with

Fields.ActionPlaySound(SoundFilename As String, RepeatCount as Long)

Function: Plays a beep or specified wav file. Can be repeated for x times or until cancelled.
Input parameters: SoundFilename as string, RepeatCount as long
Return value: None

Specifying a empty string ("") for SoundFilename will result in the system beep sound.

RepeatCount options:
0 = repeat until cancelled (Cancel by pressing flashing bell on main display window)
1 to 100 = repeat specified number if times, or until cancelled manually

When the repeat count is greater than 1, the wav file or beep sound will be played at 5 second intervals.


Example usage:
' Play the squeak sound 5 times
Call Fields.ActionPlaySound("C:\Program Files\Syslogd\Sounds\Squeak.wav", 5)

' Play the squeak sound until cancelled
Call Fields.ActionPlaySound("C:\Program Files\Syslogd\Sounds\Squeak.wav", 0)

' Play the system beep sound 10 times
Call Fields.ActionPlaySound("", 10)

' Play the system beep sound until cancelled
Call Fields.ActionPlaySound("", 0)


Fields.ActionSendEmail(MailTo, MailFrom, MailSubject, MailMessage)

Function: Sends an e-mail to the addresses specified
Return value: None

To send the message to multiple addresses, separate each address with a comma.

E.g.:

MailTo = "user1@company.com,user2@company.com,user3@company.com"

Example usage:

MailTo = "joe@company.com"
MailFrom = "server@company.com"
MailSubject = "This is a test of the scripting action"
MailMessage = "This is a test mail message" & vbCrLf & "Multiple lines."

Call Fields.ActionSendEmail(MailTo, MailFrom, MailSubject, MailMessage)


Fields.ActionLogToFile(Filename, Data)

Function: Opens the specified log file and appends the Data to the end of the file.
Return value: None

This function can be used to log messages to file in your own format.

AutoSplit syntax values can be used in the filename if you want.
To have the filename contain the current hour of the day, use %TimeHH

Example: Filename = "C:\Program files\Syslogd\Logs\TestLog%TimeHH.txt"


Example usage:

Filename = "C:\Program files\Syslogd\Logs\TestLog.txt"
MsgPriority = "Local7.Info"
MsgHostAddress = Fields.VarPeerAddress
' Use the date and time from the current message
MsgDate = Fields.VarDate & " " & Fields.VarTime 
MsgText = "This is a test message from the scripting action"
Data = MsgDate & vbtab & MsgPriority & vbtab & MsgHostAddress & vbtab & MsgText

Call Fields.ActionLogToFile(Filename, Data)

Note: this example requires that Read permission be enabled for "Other fields". This gives the script read access to the VarDate and VarTime variables.


Fields.ActionSendSyslog(Hostname, Message, Port, Protocol)

Function: Sends a syslog Message to Hostname on Port via Protocol.
Return value: None

Hostname: Text string containing the hostname or IP address of the remote host.
Message: Text string containing the priority tag and syslog message text
Port: Integer between 1 and 65535 (514 is the standard syslog port)
Protocol: Integer between 0 and 1 (0=UDP, 1=TCP)

This function can be used to send syslog messages to another syslog host via the UDP or TCP protocol.

Example usage:

Hostname = "10.0.0.1" ' Remote syslog host
Priority = 191        ' Local7.Debug
Port = 514            ' Use the standard syslog port
Protocol = 0          ' 0=UDP, 1=TCP
' Construct the syslog message by adding <PRI> value to the front of the text
Message = "<" + Cstr(Priority) + ">" + "This is an example of a syslog message"

Call Fields.ActionSendSyslog(Hostname, Message, Port, Protocol)


Fields.ActionLogToFileWithCache(Filename, Data)

Function: Writes data to the specified log file. This function uses a write cache to improve performance. The cache is flushed every 100 messages or 5 seconds, which ever comes first. The cache settings can be adjusted via registry settings. This function is exactly the same as ActionLogToFile, except that it uses a write cache. We recommend the use of the write caching function when you are receiving more than 10 messages per second.
Return value: None

This function can be used to log messages to file in your own format.

AutoSplit syntax values can be used in the filename if you want.
To have the filename contain the current hour of the day, use %TimeHH

Example: Filename = "C:\Program files\Syslogd\Logs\TestLog%TimeHH.txt"


Example usage:

Filename = "C:\Program files\Syslogd\Logs\TestLog.txt"
MsgPriority = "Local7.Info"
MsgHostAddress = Fields.VarPeerAddress
' Use the date and time from the current message
MsgDate = Fields.VarDate & " " & Fields.VarTime 
MsgText = "This is a test message from the scripting action"
Data = MsgDate & vbtab & MsgPriority & vbtab & MsgHostAddress & vbtab & MsgText

Call Fields.ActionLogToFileWithCache(Filename, Data)

Note: this example requires that Read permission be enabled for "Other fields". This gives the script read access to the VarDate and VarTime variables.


Fields.ActionDeleteFile(Filename)

Function: Attempts to delete the specified file.
Return value: None

This function can be used to delete a log file to ensure a fresh start.

This function does not support wildcards, a specific file name must be specified. No confirmation is required, so be careful when using this function.

Example usage:

Filename = "C:\Program files\Syslogd\Logs\TestLog.txt"
Call Fields.ActionDeleteFile(Filename)


Fields.ActionDisplay(DisplayNumber, TabDelimitedMessage)

Function: Displays a message to the specified virtual display number.
Return value: None

This function can be used to display messages on the screen in your own format.

The TabDelimitedMessage must contain 5 tab delimited fields. The contents of each field can be anything you like. The normal display fields are: Date TAB Time TAB Priority TAB Hostname TAB Message.


Example usage:

With Fields
      MsgPriority = ConvertPriorityToText(.VarPriority)
      MsgHostAddress = .VarPeerAddress
      ' Use the date and time from the current message
      MsgDate = .VarDate & " " & .VarTime 
      MsgText = "This is a test message from the scripting action"
      Display = MsgDate & vbtab & MsgTime & vbtab & MsgPriority & vbtab &_
                MsgHostAddress & vbtab & MsgText
      Call .ActionDisplay(0, Display)
End with


Fields.ActionLogToODBC(DSNString, TableName, InsertStatement, Timeout)

Function: Passes the InsertStatement to the database specified by DSNString and TableName. The timeout specifies how many seconds to keep the database connection open when idle.

Return value: For success, an empty string is returned. Otherwise the error is passed back as a string value.

This function can be used to log messages to a database in your own format. The connection to the database is held open internally to the program. This avoids the overhead of creating and breaking the connection each time data is sent. If no further data is sent to the database, once the timeout period has elapsed, the connection will be closed. The next time data needs to be sent, the connection will be reopened.

Example usage:

In the case of this example, a System DSN called "KiwiSyslog" has been created and points to a MS Access database. The SQL insert statement syntax changes slightly depending on the database type being written to. The example here has only been tested on MS Access 97 and 2000.

This example assumes that a table called "Syslogd" has already been created and contains all the required fields.

MyDSN = "DSN=KiwiSyslog;"
MyTable = "Syslogd"
MyFields = "MsgDate,MsgTime,MsgPriority,MsgHostname,MsgText"

' MS Access DB SQL INSERT command example: 
' INSERT INTO Syslogd (MsgDate,MsgTime,MsgPriority,MsgHostname,MsgText) 
' VALUES ('2004-08-08','13:26:26','Local7.Debug','host.company.com',
' 'This is a test message from Kiwi Syslog Daemon')

With Fields
     ' Construct the insert statement
     SQLcmd = "INSERT INTO " & MyTable & " (" & MyFields & ") VALUES (" & _
     Quote(.VarDate) & "," & Quote(.VarTime) & "," & _
     Quote(.ConvertPriorityToText(.VarPriority)) & "," & _
     Quote(.VarPeerAddress) & "," & Quote(.VarCleanMessageText) & ")"
     ' Log the data to database using DSN, Table, SQLcmd and Timeout of 30 seconds
     .VarCustom01 = .ActionLogToODBC(MyDSN, MyTable, SQLcmd, 30)
     ' VarCustom01 now holds the return value from the function.
End with

Function Quote(Data)
    ' Replace all occurrences of ' with '' to escape existing quotes
    ' Wrap data with single quotes    
    Quote = "'" & Replace(Data, "'", "''") & "'"
End Function

Note: This example requires that Read permission is enabled for "Other fields". This gives the script read access to the .VarDate and .VarTime variables.

Note: There are more example scripts installed in the \Scripts sub folder.