Info |
---|
This document provide a detail steps on how to setup 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]
How to
...
Monitor Channel Status in Translator Translator to alert Iguana Monitoring
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.
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. |
Code Block |
---|
function main()
-- Retrieve status
local status = iguana.status()
-- Parsed status
local parsedStatus = xml.parse{data=status}
local iguanaParsedStatus = parsedStatus.IguanaStatus
-- Number of channels in instance
local count = iguanaParsedStatus:childCount("Channel")
-- List (table) to hold all stopped channel names
local stopped = {}
-- Loop over the status page of Iguana and find all the stopped channels and insert them to table
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
-- If there are channels stopped then create a warning log
if (#stopped > 0) then
-- The header will be at the top of the warning
local warningHeader = "The following channels are off:\n\n"
-- Followed by all the channel names
local warningBody = table.concat(stopped, "\n")
-- Finally call the function and concatenate the header and the body
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”.
...