Scripting tutorial — Legacy
This documentation is for legacy Kiwi Syslog Server versions 9.8.3 and older.
This tutorial demonstrates how to create a script and use it to search and replace text within a syslog message.
The scripting action is available only in the registered version of Kiwi Syslog Server Service Manager.
Each of the four tasks outlined below must be completed in sequential order to successfully create and execute the tutorial script.
Task 1: Create the script action in Setup
- Open Setup window from the File menu.
- Create a rule called Replace text.
- Add a Run Script action.
- Set the script file name to:
ReplaceText.txt
. - Set the Script Description field to
Replaces occurrences of "cat" with "dog".
- Set the Script Language to
VBScript
. - Set the Field Read/Write permissions to:
- Common fields: Read = Checked, Write = Checked
- Other fields: Read = Unchecked, Write = Unchecked
- Custom fields: Read = Unchecked, Write = Unchecked
- Click the Edit Script button to open the file in Notepad. Because the file does not exist, you will be prompted to create a file.
-
Copy and paste the following script file into Notepad and Save.
Function Main()
' Replace cat with dog within the message text field Fields.VarCleanMessageText = Replace(Fields.VarCleanMessageText, "cat", "dog")
' Return OK to tell syslog that the script ran correctly.
Main = "OK"
End Function
Task 2: Create the log to file actions
- Return to Replace Text rule created in Task 1.
- Add a Log to file action.
- Enter the Path and file name of log file as:
MyCustomLog.txt
in a folder. - Leave the log file format as the default:
Kiwi format ISO yyyy-mm-dd (Tabdelimited)
. - Click the action and then press F4 to auto name the action
Log to file
. - Add a Display action.
- Leave the display number as the default:
Display 00 (Default)
. - Click the action and then press F4 to auto name the action
Display
.
The Run script action should be listed above the Display and Log to file actions. If not, you can select the action and use the ^ toolbar button to move it up the list.
Your rule should look like this:
Rules
Rule: Replace Text
Filters
Actions
Run Script
Display
Log to file
Task 3: Test the script
- Select the Run Script action.
- Click the Test Setup button.
- Change the message text to read:
The cat sat on the mat
. - Click the Show action button.
- Check the Show test results check box.
- Press the Test button.
After the script runs, the results open in Notepad. There you see the script variables. Check the VarCleanMessageText field and you should see the word "cat" has been changed to "dog."
Task 4: Test the script with SyslogGen
- To apply the rule changes, click OK on the Kiwi Syslog Server Setup window.
- Download SyslogGen from http://www.kiwisyslog.com/downloads.aspx and install it on the same machine as the Syslog Server.
- Set the send options to
send message once
. Set the destination tolocalhost (127.0.0.1)
. - Set the message text to "This is a test. The cat sat on the mat."
- Press the Send button.
The message: "This is a test. The dog sat on the mat." is displayed.