How to monitor stopped Iguana Channels
This document provides steps on how to setup an Email alert when a production Iguana’s channels are down/off. Note: we assume you have basic knowledge on how to setup a From Translator channel. All code below is intended for demo purposes.
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 these logs come in.
How to Monitor Channel Status in Translator
From the dashboard, add a From Translator channel (for this example, I will call it Channel Monitor) and for the Destination you can select To Channel (you can leave it empty).
Update the poll time (default is 10 seconds) under Source in the channel settings appropriate to your email monitoring needs.
Input the following snippet of code in the translator, the code works as follows:
It uses the iguana.status() API to retrieve the Iguana status (which includes channel status) and parse the data.
Next it will check for any stopped channels.
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).
-- 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 warning in Iguana logs
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
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:
Go to settings then Monitoring. You may have to setup your email settings, please visit this page for more information. Monitoring - iNTERFACEWARE Help Center
If your email settings are already 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) then 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.
Once you’re done, you will receive an email that resembles the following in the case a channel is down however, please make sure you thoroughly test your Monitoring channel before deploying it:
Considerations
The previous monitoring example only works for local Iguana channels as the iguana.status() function only returns the status of local 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.
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 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.