Using Iguana to Monitor Channels

You can use Iguana to monitor channels and start and stop them when necessary and you can find the details on how to do this in our manual   This article was created to present you with a small example for how to complete this task as well as a module that can assist to make it easier straight away.    The module here will monitor a whole Iguana server and start any channel that is not up and running as well as log a ‘Warning’ in the logs identifying that the channel needed to be restarted.  You could enhance this use by creating an email notification rule based upon the log entry so that you know when a channel had to be restarted, you could adjust the script to only start channels with a certain name, or really anything else you can dream up.

You can download the project here; Monitor_Iguana_Server_From_Translator.zip if you would like to see the module in action or manually copy and paste the module below to begin your customized use.

To setup this project you would complete the following steps:

  1. Create a new channel.
    • Source        = ‘From Translator’
    • Destination = ‘To Channel’
    • Name         = ‘Iguana Monitor’
  2. Click ‘Edit’ Script’ on Source Tab.
  3. Choose Import Project from Zip file, select the downloaded zip file from above, and click ‘Import’.
  4. Adjust the configuration settings at the top:
    • –CUSTOM CONFIGURATION PORTION
      Iguana = <Your Server IP and Port here>
      user   =  <Your User Name>
      pass   = <Your Password>

Below is a copy of the ‘monitor’ script.  In order to use this you would create a new shared module and name it ‘monitor’ then copy and paste the code below and require ‘monitor’ at the top of your main script.  (I have built in a help menu along with this to make utilizing it even easier).

function iguana.checkServerStatus(args)
   local srv = args.server
   local usr = args.username
   local pas = args.password

   return xml.parse{data=net.http.get{
         live=true, timeout=60,
         url=srv..[[/status.html]],
         auth={username=usr, password=pas},
         parameters={Format='xml'}}
   }
end --end of checkServer

function iguana.restartChannel(args)
   local srv = args.server
   local usr = args.username
   local pas = args.password
   local nme = args.channel
  --restart channel
   net.http.get{url=srv..[[/status.html]],
      auth={username=usr, password=pas},
      parameters={ChannelAction='Start', ChannelName=nme},
      live=false
   }
  --log a warning SETUP AN EMAIL NOTIFICATION IF YOU WANT ALERTED
   iguana.logWarning([[Channel ]]..nme..[[ is down and being restarted.]])
end --end of restartChannels

help_checkServerStatus = {
   Title="iguana.checkServerStatus";
   Usage=[[iguana.checkServerStatus{server=< value > , username=< value >, password=< value >}]],
   Desc=[[Checks the Iguana server to get all the channels and their statuses.
   ]];
   ["Returns"] = {
      {Desc="Table with all channel names and statuses."},
   };
   ParameterTable= true,
   Parameters= {
      {server= {Desc=[[The Iguana server URL (ex. 'http://192.168.1.1:6543').]]}},
      {username= {Desc='Iguana server username with authorization to start channels.'}},
      {password= {Desc='Iguana server user password needed to authorize channel start.'}}
   };
   Examples={
      [[iguana.checkServerStatus{
      server='192.168.1.1:6543', 
      username='admin', 
      password='password'
      }
   ]],
   };
   SeeAlso={
      {
         Title="Monitoring an Iguana Instance with Iguana",
         Link="http://wiki.interfaceware.com/190.html"
      },
      {
         Title="Starting and Stopping Channels Using a Web URL",
         Link="http://www.interfaceware.com/manual/starting_and_stopping_channels_using_a_web_url.html"
      }
   }
}

help_restartChannel = {
   Title="iguana.restartChannel";
   Usage=[[iguana.restartChannel{server=< value > , username=< value >, password=< value >, channel=< value >}]],
   Desc=[[Restarts the channel that you specify on the server you designate as well as logs
   a warning into the logs identifying the channel that was restarted which is good for setting up and receiving email notifications..
   ]];
   ["Returns"] = {
      {Desc="nothing."},
   };
   ParameterTable= true,
   Parameters= {
      {server= {Desc=[[The Iguana server URL (ex. 'http://192.168.1.1:6543').]]}},
      {username= {Desc='Iguana server username with authorization to start channels.'}},
      {password= {Desc='Iguana server user password needed to authorize channel start.'}},
      {channel= {Desc='Iguana Channel name, as a string, to start.'}}
   };
   Examples={
      [[iguana.restartChannel{
      server='192.168.1.1:6543', 
      username='admin', 
      password='password',
      channel='Iguana Channel Name'}
   ]],
   };
   SeeAlso={
      {
         Title="Monitoring an Iguana Instance with Iguana",
         Link="http://wiki.interfaceware.com/190.html"
      },
      {
         Title="Starting and Stopping Channels Using a Web URL",
         Link="http://www.interfaceware.com/manual/starting_and_stopping_channels_using_a_web_url.html"
      }
   }
}

help.set{input_function=iguana.checkServerStatus,help_data=help_checkServerStatus}
help.set{input_function=iguana.restartChannel, help_data=help_restartChannel}