Info |
---|
Recently, some customers approached us asking whether Iguana can alert when a production Iguana channels is down/off. The answer is yes you can! You can use Iguana Monitoring and the Translator to achieve that goal very easily. |
How to use 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“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 - in other wordsto 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 at most 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).1000 ms is 1 s
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”.
...
The channel is now ready to start monitoring. You can start it now, or feel free to start it once you setup Iguana monitoring as it is only logging alert messages if Iguana Monitoring is not set up.
How to Setup Email Notification in Iguana Monitoring
...
Considerations
...
To set up email notifications, you can do the following:
From your dashboard, go to settings in the top right corner.
Scroll down to “Monitoring” under “System Settings”, 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):
...
Select your email recipients under “Recipients” and click on Save Changes.
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.
Considerations
The previous monitoring example only works for local Iguana channels as the iguana.status() function returns the status of all Iguana channels that are currently on the same instance as the translator calling the function. 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 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 check next to the “off” check to see if a channel is off AND is in the target table or not.