Howto:Monitor device uptime and gather traces with trap information via automated script: Difference between revisions

From innovaphone wiki
Jump to navigation Jump to search
mNo edit summary
Line 9: Line 9:


==More Information==
==More Information==
In some cases a gateway or a phone may become instable due configuration or firmware bug resulting in a not predictable  
In some cases a gateway or a phone may become instable due to configuration or firmware bugs resulting in not predictable  
 
restarts of the device. In this case my be useful for diagnosis to download a trace from the device right away.  
restart of the device. In this case it is very important to download a trace from the device and to provide it to the
 
development, so the reason of the trap can be encountered.
 
This article provides a simple PHP script for this purpose.
This article provides a simple PHP script for this purpose.


===Configuration===
===Configuration===
At first get the PHP as described in related article.
At first get and install the PHP as described in the related article.
 
Then create a new file called '''uptime.php''' with following code in it:
After that create a new file called '''uptime.php''' with following code in it:


<code php>
<code php>
Line 83: Line 78:


Open a command prompt and change to the location you stored '''uptime.php''' in. In our example it is the same directory we  
Open a command prompt and change to the location you stored '''uptime.php''' in. In our example it is the same directory we  
have extracted PHP to.
have extracted PHP to.


Line 91: Line 85:




The script will run until you stop it with '''Ctrl+C'''. In case any of devices provided in script perform a reboot a trace  
The script will run until you stop it with '''Ctrl+C'''. In case that any of the devices listed in <code>$pbx_ips</code> performs a reboot, a trace  
 
will be dowloaded in the current directory.
will be dowloaded in the current directory.


===Known Problems===
===Known Problems===
To run this script on a web server set '''$loop''' to false.
To run this script on a web server (thus polling all listed devices once on each refresh of this page), set '''$loop''' to false.


== Related Articles ==
== Related Articles ==

Revision as of 09:33, 24 November 2008

This article provides an example script used to download a trap trace in a short time after device reboot.

Applies To

This information applies to

  • all innovaphone devices


More Information

In some cases a gateway or a phone may become instable due to configuration or firmware bugs resulting in not predictable restarts of the device. In this case my be useful for diagnosis to download a trace from the device right away. This article provides a simple PHP script for this purpose.

Configuration

At first get and install the PHP as described in the related article. Then create a new file called uptime.php with following code in it:

<?php // PBX ip addresses $pbx_ips = array( "192.168.0.1", "192.168.0.2" );

// admin username $user = "admin"; // admin password $pass = "ip6000";

//loop script $loop = true;

//$DEBUG = true; $DEBUG = false;

// GET request $get_uptime = "/CMD0/mod_cmd_no_pwd.xml?cmd=box-info&xsl=box_info.xsl"; $get_trace = "/log.txt";

while($loop){

   foreach($pbx_ips as $pbx_ip){
       //URL
       $url_uptime = "http://".$pbx_ip.$get_uptime;
       $url_trace = "http://".$user.":".$pass."@".$pbx_ip.$get_trace;
      
       if ($DEBUG) echo "GET ".$url."\r\n";
  
       // get XML Object List form PBX
       $xml_string = file_get_contents($url_uptime);
  
       // convert to UTF-8, create SimpleXMLElement
       $xml = new SimpleXMLElement(utf8_encode($xml_string));
  
       if ($DEBUG) echo "Uptime ".$pbx_ip." ".$xml->sys['uptime']." s.\r\n";
      
       if ($xml->sys['uptime'] < 20){
           $current_datetime_log = date("d.m.Y H:i:s",time());
           $current_datetime_file = date("d.m.Y-H-i-s",time());
          
           $message = $current_datetime_log." ".$pbx_ip." ALARM uptime ".$xml->sys['uptime']." seconds!!!\r\n";
           echo $message;
           file_put_contents("traps.txt",$message, FILE_APPEND);
           $trace_text = file_get_contents($url_trace);
           file_put_contents("trace-".$pbx_ip."-".$current_datetime_file.".txt",$trace_text);
       }
   }
   if ($DEBUG) echo "Sleep 20 s.\r\n";
   if($loop) sleep(20);

} ?>

You have to change $pbx_ips, $user and $pass.

Usage

Open a command prompt and change to the location you stored uptime.php in. In our example it is the same directory we have extracted PHP to.

Now you can run the script:

C:\Temp\php-5.2.5-Win32> php.exe uptime.php


The script will run until you stop it with Ctrl+C. In case that any of the devices listed in $pbx_ips performs a reboot, a trace will be dowloaded in the current directory.

Known Problems

To run this script on a web server (thus polling all listed devices once on each refresh of this page), set $loop to false.

Related Articles

Howto:Export_PBX_userlist_from_PBX_with_e164_numbering_schema