Introducing KNM Lua scripting

Tech Notes

Kaseya Network Monitor includes support for the Lua scripting language. Lua is a powerful light-weight programming language designed for extending applications. With Lua customers can create custom made monitors to test systems and equipment not supported by any built-in monitor.

  • New monitors, actions and events can be created and tested in the development environment provided by Kaseya, before they are exported and used in Kaseya Network Monitor.
  • A comprehensive library of pre-made classes, such as SFTP client, HTTP client and file management, are available to developers.
  • The develop environment includes debugger, keyword highlighting, integrated help and other features available in state-of-the-art development tools.

Included scripts

In the default KNM installer there are a number of bundled scripts. The scripts are located in the “script” directory in the KNM folder. The included scripts is a great place to start if you want learn to develop your own script.

ApacheStatus_.lua
Monitors work threads in a Apache web server

BackupExec_.lua / BackupExec_11D_.lua
Monitors the completion status of backup jobs.

CheckCertificateExpiryTime_.lua
Checks if a HTTP certificate is about to expiry, the period can be set in days.

CiscoIPSecGlobalTunnelBandwidth_.lua
Monitors the bandwidth usage of all IPSec tunnels open on a firewall.

CiscoIPSecTunnelBandwidth_.lua
Monitors the bandwidth of a specific (named) IPSec tunnel.

iLoHealth_.lua
Monitors health status parameters of an HP iLo2 watchdog computer.

PrinterOutOfPaper_.lua
Checks if a Windows attached printer is out of paper.

WBEM_ESXi_HP_Fan_Status_.lua
WBEM_ESXi_HP_PSU_Status_.lua
WBEM_ESXi_HP_RaidArray_Status_.lua
Monitors VMWare ESXi hardware parameters (Fan, raidarray and PSU health status)

Steps to start developing scripts

First you need to download the Lua IDE. Its shipped with KNM and all you need to do is to logon to the KNM web interface and go to the “About page”.

About page

Click on the Lua IDE link and download the installer. Start the installer and follow the instructions on screen. When the installer is done, located the Lua IDE in the start menu and start it.

Lua IDE with template script

Scripts written must adhere to the programing model of KNM, to get started quickly and avoid writing boilerplate code, you can use a script template. In the menu “Insert code” , click the “insert template script” menu item.

Before we can run the debugger and test this boilerplate code, we need to add a new host. KNM Lua script is always run in the context of a host. API calls are always relative to a host, meaning that its not possible to perform actions against different machines in the same insttance of a script. Therefore before starting a debugging session we always need to select a host.

Click the “Open host list” in the tool bar and add a host by entering it the text field below the list and click “Add host”.  When added, select it in the list and click the “select host” button.

Add a new host

To test the template scripts just inserted into the empty document, click on the cogwheel in the tool bar or hit CTRL+F5 to start a new debugging session.

Debugging the template script

The script will be executed by the IDE the exact same way KNM will execute it, the interface will be emulated using standard windows controls.

To learn more about using the IDE and the Lua API, open the link below.

Click here to open the Lua  API documentation.

How to deploy and use a script

When you are happy with your script its time to deploy it to KNM.

  1. Located the script on your computer
  2. Copy the script to the “script” directory in the KNM folder
  3. Done

When deployed to KNM it can be used in the Lua script monitor.

Lua Monitor property page
  1. Select a object and open up its object info page
  2. Click New monitor
  3. Select Lua script in the script category
  4. Select the script from the drop down list in the “Lua script monitor properties” section.
  5. Configure the script parameters
  6. Done

Note that when selecting a script, it permanently removes the option to select another script, if you need to use a different script, create a new monitor for that script.

Hope this mini-tutorial have been helpful, the Lua API opens up a lot of possibilities to monitor company specific processes and systems.

Please let us know if you´ve written a script that you want to share !

Man using VR headset

CompTIA State of the Channel Study Points to Bright MSP Future

Channel advocacy group CompTIA tracks the MSP market as well as the overall IT space. The group has been coveringRead More

Security Collage

9 Top Security Predictions from Gartner– Plus Advice!

As a leading analyst firm, Gartner comes out with a steady stream of predictions. One of the latest rounds concernsRead More

Is the Trusted Advisor Still the Pinnacle of MSP-Dom?

The term ‘trusted advisor’ has been perhaps a bit overused, maybe way way overused. Even abused. But that doesn’t diminishRead More

CSI: Kaseya (or How to Protect Corporate Data When A Laptop is Stolen)

Earlier this week, Premier Healthcare, a Bloomington, Indiana-based healthcare provider, reported a data breach that could affect over 200,000 peopleRead More

Connect IT Asia-Pacific - Don't Miss the Premier IT Management Event of the Year - Join Us in Sydney 1-3 October 2019 - Register Now

Archives

Categories