Info |
---|
This document provide a detail provides steps on how to setup an Email alert when a production Iguana channels are down/off. Note: we assume you have basic knowledge on how to setup From Translator. All code below is intended for demo purpose.
|
[Demo Video Here]The main idea is to utilize a From Translator polling channel to log a warning whenever a channel is down and for Iguana Monitoring to watch for such logs and send an email whenever a these logs come in.
How to Monitor Channel Status in Translator
...
The main idea is utilize a polling channel to get the status of the channels using the iguana.status() or /status APIs every x amount of time. To set up a polling channel, do the following:
From the dashboard, click on Add Channel. For the source select “From Translator” and for the Destination select “To Channel” and click “Start Configuring”.
Add a channel name (for the sake of this example, we’ll choose “Channel Monitor”) and a description that will help you identify the channel later.
Under source, input a polling time (how often is the main function script called - to explain, let’s say you start the channel at 3:00 PM and set the polling time to 1800000 milliseconds (ms) which is 30 minutes, you the channel will check for off channels at 3:30 PM then again at 4:00 PM and so on… You will receive an email every 30 minutes or every x amount of time depending on how long you set the polling at in the case a channel was off for a long time).
For your reference, 1,000 ms = 1 second, 900,000 ms = 15 minutes, 180,000 = 30 minutes and so on… You can set the polling time to any number you prefer (minimum is 1000)
Once the channel is created, go to the Source tab and click on Edit Script to start coding in the monitoring functionality. The “Import Project” channel will come up, you can select “Use a blank project” and click “Import”.
Below is the sample code I used to create a simple monitoring channel, in a nutshell, it calls the iguana.status() function which returns a lot of useful information about the current Iguana instance including channel status (on/off). The channel then finds all the channels that are “off” and puts them in a list, if this list is not empty, it logs a warning message so Iguana Monitoring can read it and send out an email accordingly.
...
add a new channel (for this example, I will call it Channel Monitor) with a From Translator component and for the Destination you can select to Channel (you can leave it empty).
Select a poll time under Source in the channel settings appropriate to your needs.
Input the following snippet of code in the translator, the code works by utilizing the iguana.status() API to retrieve the Iguana status (which includes channel status). Next it will check for any stopped channels and finally it will log a warning message using iguana.logWarning with a header and the names of the channels. (The header will be used in Iguana monitoring to detect the warnings).
Code Block |
---|
-- Get all channel status and log stopped channels in Iguana Log
function main()
-- 1) Retrieve status
local status = iguana.status()
-- 2) Parsed status and count |
...
all channels local parsedStatus = xml.parse{data=status} local iguanaParsedStatus = parsedStatus.IguanaStatus local count = iguanaParsedStatus:childCount("Channel") -- 3) Find all the stopped channels local stopped = {} for i = 1, count do if iguanaParsedStatus:child("Channel", i).Status:nodeValue() == 'off' then table.insert(stopped, iguanaParsedStatus:child("Channel", i).Name:nodeValue()) end end -- 4) Create a stopped channel warnings in Iguana log if (#stopped > 0) then local warningHeader = "The following channels are off:\n\n" local warningBody = table.concat(stopped, "\n") iguana.logWarning(warningHeader .. warningBody) end end |
...
Then click on commit to source then add a note message at the bottom then click on “Commit Files”. Check “Update to run from new commit” if it pops up and click “Update”.
...
Note |
---|
Please note that this is only an example intended to show Iguana’s capabilities. You may need to modify this code or do some further testing to make sure this fit your requirements. |
This will generate logs that look like this:
...
The next step is to setup Iguana Monitoring to watch for these warnings and send out an email whenever they are detected.
How to Setup Email Notification in Iguana Monitoring
To set up email notifications, you can do the following:
From your dashboard, go Go to settings in the top right corner.Scroll down to “Monitoring” under “System Settings”, you then Monitoring. You may have to setup your email settings, please visit this page for more information: . https://help.interfaceware.com/v6/monitoring#settings
Click on Notification Rules then Add a Rule, input the following settings (please note that if you change the code above, you may have to change the rule accordingly):
...
If your email is setup, add a new notification Standard Rule.
Select the source and channel to be your ‘Channel Monitor’ and note that you will be querying the logs of that channel for Warnings that contain the header ("The following channels are off” - Line 21 in the example code) and select your recipients. Your rule should look something like this:
...
Your monitoring channel should be good to go! Go ahead and start the channel from the dashboard if you did not start it already and it should start monitoring and sending out emails when channels are down.
...
The previous monitoring example only works for local Iguana channels as the iguana.status() function only returns the status of all Iguana channels that are currently on the same instance as the translator calling the functionlocal channels. One way to monitor external Iguana instances is by utilizing http calls to the /status API, it will returns the exact same data as the iguana.status() function.
Another consideration to keep in mind is that this This snippet of code will monitor ALL the channels in the instance. In the case you only need to monitor a small group, you may need to implement some changes to only monitor certain channels. A relatively easy way to do this would be by hardcoding some channel names in a “target” table, and adding another target add a check next to the “off” check to see if a channel is off AND is in the target table or not on line 14.