Hello all Has anyone had any success with the Manager API ? I am trying to check an extension status without too much luck I have the following <?php $fp = fsockopen("127.0.0.1", 5038, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "Action: Login\r\n"; $out .= "UserName: simon\r\n"; $out .= "Secret: xxxxxx\r\n\r\n"; fwrite($fp, $out); $in = "Action: ExtensionState\r\n"; $in .= "Exten: 4367\r\n\r\n"; $in .= "Context: office\r\n\r\n"; $in .= "ActionID: \r\n\r\n"; $in .= "Action: Logoff\r\n\r\n"; fwrite($fp,$in); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } ?> The first prob is it ignores the Context and just goes to default. The second is anyone know what ActionID is ? Best Regards Simon ----------------------------------------------- This message has been scanned for viruses and dangerous content by OrbitalNet, and is believed to be clean. If you have any concerns with this message please email us, support@orbital.net / http://www.orbital.net -----------------------------------------------
Simon wrote:>Hello all > >Has anyone had any success with the Manager API ? > >I am trying to check an extension status without too much luck I have >the following > ><?php > > > $fp = fsockopen("127.0.0.1", 5038, $errno, $errstr, 30); > if (!$fp) { > echo "$errstr ($errno)<br />\n"; > } else { > $out = "Action: Login\r\n"; > $out .= "UserName: simon\r\n"; > $out .= "Secret: xxxxxx\r\n\r\n"; > > fwrite($fp, $out); > $in = "Action: ExtensionState\r\n"; > $in .= "Exten: 4367\r\n\r\n"; > $in .= "Context: office\r\n\r\n"; > $in .= "ActionID: \r\n\r\n"; > $in .= "Action: Logoff\r\n\r\n"; > fwrite($fp,$in); > while (!feof($fp)) { > echo fgets($fp, 128); > } > fclose($fp); > } > > ?> > >The first prob is it ignores the Context and just goes to default. >The second is anyone know what ActionID is ? > >Best Regards >Simon > > > >----------------------------------------------- >This message has been scanned for viruses and >dangerous content by OrbitalNet, and is >believed to be clean. If you have any concerns >with this message please email us, >support@orbital.net / http://www.orbital.net >----------------------------------------------- > >_______________________________________________ >Asterisk-Users mailing list >Asterisk-Users@lists.digium.com >http://lists.digium.com/mailman/listinfo/asterisk-users >To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users > >Here is the php code that works for me: I use this to get a list of extensions that are in use. $socket = fsockopen("127.0.0.1","5038", $errno, $errstr, $timeout); fputs($socket, "Action: Login\r\n"); fputs($socket, "UserName: xxxxxxx\r\n"); fputs($socket, "Secret: xxxxxxx\r\n\r\n"); fputs($socket, "Action: command\r\n"); fputs($socket, "Command: show channels\r\n\r\n"); fputs($socket, "Action: Logoff\r\n\r\n"); while (!feof($socket)) { $wrets = fgets($socket, 4096); $wrets = trim($wrets); if(substr($wrets,0,3)=="SIP"){ $m_start = strpos($wrets,'/'); $m_end = strpos($wrets,'-'); $m_ext = substr($wrets,$m_start+1,($m_end-$m_start)-1); //do something here with the extension number } if(substr($wrets,0,4)=="IAX2"){ $m_start = strpos($wrets,'/'); $m_end = strpos($wrets,'@'); $m_ext = substr($wrets,$m_start+1,($m_end-$m_start)-1); //do something here with the extension number } } fclose($socket); I think ActionID is just an ID number for your own use. Malcolm
<< Has anyone had any success with the Manager API ?>> Yes, lots of success. I think we found that tracking the status of an extension is the most reliable way to monitor extension state. We do issue a PeerStatus request at the beginning but that's pretty time and resource intensive. Since the Manager is going issue status events anyway, we monitor them and save the resources. << The second is anyone know what ActionID is ?>> Yes, ActionID is a value you can use when issuing a command. It there so that you can be sure you respond to your own responses not to someone else's or that you respond to an response instance in the correct way. In a multi-threaded app you might have several actions outstanding so you will need to know what response corresponds to which command. Bill Seddon -----Original Message----- From: asterisk-users-bounces@lists.digium.com [mailto:asterisk-users-bounces@lists.digium.com] On Behalf Of Simon Sent: January 13, 2005 4:56 PM To: asterisk-users@lists.digium.com Subject: [Asterisk-Users] Manager API !!!!!!!!! Hello all Has anyone had any success with the Manager API ? I am trying to check an extension status without too much luck I have the following <?php $fp = fsockopen("127.0.0.1", 5038, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "Action: Login\r\n"; $out .= "UserName: simon\r\n"; $out .= "Secret: xxxxxx\r\n\r\n"; fwrite($fp, $out); $in = "Action: ExtensionState\r\n"; $in .= "Exten: 4367\r\n\r\n"; $in .= "Context: office\r\n\r\n"; $in .= "ActionID: \r\n\r\n"; $in .= "Action: Logoff\r\n\r\n"; fwrite($fp,$in); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } ?> The first prob is it ignores the Context and just goes to default. The second is anyone know what ActionID is ? Best Regards Simon ----------------------------------------------- This message has been scanned for viruses and dangerous content by OrbitalNet, and is believed to be clean. If you have any concerns with this message please email us, support@orbital.net / http://www.orbital.net ----------------------------------------------- _______________________________________________ Asterisk-Users mailing list Asterisk-Users@lists.digium.com http://lists.digium.com/mailman/listinfo/asterisk-users To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
On Thu, Jan 13, 2005 at 04:56:05PM -0000, Simon wrote:> Hello all > > Has anyone had any success with the Manager API ? > > I am trying to check an extension status without too much luck I have > the followingYou can supply an ActionID in your request to track the response. This is most useful if your program gets out of sync with the management protocol. If you always specify and check the ActionID on the response, you'll know that you're retrieving the correct response. -- Jayson
Thanks to all , I have now managed to get the ExtentionState to return a Status value BUT. It seems to always return -1 whether the phone is on a call or not. Am I missing something ? I would have thought it should return some other value when the line is engaged OR am I looking at completely the wrong thing to achieve my requested task. Could be cos I am fick Ta Simon ----------------------------------------------- This message has been scanned for viruses and dangerous content by OrbitalNet, and is believed to be clean. If you have any concerns with this message please email us, support@orbital.net / http://www.orbital.net -----------------------------------------------