Re: [asterisk-users] How does AMI work with events ?
On Mon, Sep 05, 2011 at 02:41:50PM +0200, Jonas Kellens wrote: > I read some information and examples on the net, but they all show how > you login to the AMI, give an action and receive a response. The end. > I guess you just re-run the script every time you want the action to be > executed. > > How then does this work when you use events ? If I want to use > "PeerStatus" to monitor the state of a SIP peer, how can I run a script > on change of peer status ? [snip] > That's it. I'm logged in and I have been subscribed to receive peer > status changes. Where do these peer changes appear ? I really don't get > that. This is fairly basic stuff: 1-connect to AMI 2-authenticate 3-subscribe to events 4-listen for events 5-check if wanted event and do something with it, else 6-go back to listening So in your script you are connected, just start listening (fgets()) and check if the appropriate event arrived (keep reading lines till first empty line). Parse the event and do something (mail in your case) when required. Examples of PeerStats Events: http://www.voip-info.org/wiki/view/asterisk+manager+events#PeerStatusEvent Creating a prototype daemon in PHP should be easy, but I experienced weird hangups in PHP with longlived sockets. Personally I monitor SIP/IAX peers by parsing: asterisk -nrx "sip show peers" with Nagios/NRPE scripts. -- Daniel Tryba -- _ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- New to Asterisk? Join us for a live introductory webinar every Thurs: http://www.asterisk.org/hello asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
[asterisk-users] How does AMI work with events ?
Hello list, I don't really understand how AMI works. I read some information and examples on the net, but they all show how you login to the AMI, give an action and receive a response. The end. I guess you just re-run the script every time you want the action to be executed. How then does this work when you use events ? If I want to use "PeerStatus" to monitor the state of a SIP peer, how can I run a script on change of peer status ? If I make a php script to login and send an event, where does every status change then go to ?? //* Connection details */ $manager_host = "127.0.0.1"; $manager_user = "admin"; $manager_pass = "iamgod"; /* Default Port */ $manager_port = "5038"; /* Connection timeout */ $manager_connection_timeout = 30; /* Connect to the manager */ $fp = fsockopen($manager_host, $manager_port, $errno, $errstr, $manager_connection_timeout); $login = "Action: login\r\n"; $login .= "Username: $manager_user\r\n"; $login .= "Secret: $manager_pass\r\n"; $login .= "Event: PeerStatus//\r\n"; $login .= "\r\n"; fwrite($fp,$login);/ That's it. I'm logged in and I have been subscribed to receive peer status changes. Where do these peer changes appear ? I really don't get that. If I want to send an email on every peer status change... where do I have to look for peer status changes ? Kind regards, Jonas. -- _ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- New to Asterisk? Join us for a live introductory webinar every Thurs: http://www.asterisk.org/hello asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users