Introducing KNM Lua scripting

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 !

12 thoughts on “Introducing KNM Lua scripting

  1. Proper scripting in Kaseya! Excellent! Now i’m just hoping that this is an indication of where scripting (“procedures”) is going for Kaseya. This is like a breath of fresh air, i’m telling you.

    Thanks!
    ~rL

  2. Oops. Noob error. We’re not talking about Kaseya VSA here, the product i usually just call “Kaseya”. Well then, i’ve now done the same thing as those who call Internet Explorer “Microsoft”. And go on calling Windows “Microsoft”, and call Office “Microsoft”.

    Or call Firefox “Mozilla”.

    Duh.

    But the point stands. Bring Lua to Kaseya VSA and it will be good.

    1. Yes, Kaseya has big plans for Lua as we continue to expand our automation framework. In the next release, we are planning to offer three types of procedures: The classic Kaseya agent procedures were always meant to deliver a powerful automation capability without requiring a user to “write code.” In the next release, you will have the ability to continue to use the classic procedures which will remain compatible with prior versions of Kaseya. We will also introduce advanced procedures which will offer powerful new constructs such as case statements and do-while loops. The new constructs will be offered in an easy to use point and click procedure editor similar to today’s classic procedures. For ultimate power and flexibility, you will have the ability to create and schedule Lua scripts directly from the Kaseya Management console through a user experience similar to that described for in the Kaseya Network Monitoring blog post. You’ll be able to choose the appropriate procedure type that meets you needs. Whip out powerful ‘classic’ procedures in short order, or roll up your sleeves and go crazy with Lua.

    1. Thats odd, the error code indicates that your certificate have been revoked and the Lua HTTP client is not configured to accept secure connections with revoked certificates so it cant proceed after that.

        1. Try this:

          1. On the KNM host machine, goto IE properties
          2. Uncheck the security “Check for server certificate revocation”

  3. Hi Guys

    Im looking for someone to write me up a script for installing malwarebytes free edition for windows xp/win7 and also be able to run it. I tried creating one with the packager and application deploy and had no success. Im running G1 .

    Thanks in advance!!!

Leave a Reply

Your email address will not be published. Required fields are marked *