Was this page helpful?

[AGI] 系統故障警示語音通知

    用途:這個 PHP AGI 可以整合 nagios 或類似的其他監控軟體,做到監測系統故障的警告以語音電話方式通知。

    1. Swift 是一個商用的 Text to Speech(TTS) 的軟體,請詳見此篇 英文 TTS - Cepstral
    2. 將有關 cloudvox.com 的位址改成 localhost 或 asterisk 網路位址。
    3. nagios-callout.php 當系統異常發生時,負責撥電話,且對方接通後,系統進入 nagios-answer.php 的程序。
    4. nagios-callin.php 用戶可透過這個查詢系統有無系統異常的語音留言。
    5. nagios-answer.php 負責對異常的電話通知進行錄音。
    # When Nagios detects a problem, place an outgoing call (via Asterisk's
    # AMI protocol, PHPAGI, Cloudvox). Transfer handling to an AGI
    # (nagios-answer.php), where an admin will be told what went down and be able
    # to record a message for users/customers to hear (nagios-callin.php). Can
    # tweak to handle pretty much any alert-oriented business process.
    # When the recipient picks up the phone, send call to nagios-answer AGI:
    $callparam["Application"] = "AGI";
    $callparam["Data"] = "agi://your.computer.com/nagios_answer";
    # Set CID
    $callparam["CallerID"] = "2065558080";
    # Set variables that an AGI can access when the phone call is answered, such as
    # a user or message ID, tracking code, or any other state.
    $callparam["Variable"] = "hostname=${argv[2]}|hoststate=${argv[3]}";
    # Return immediately (true) or wait for Timeout below (false or unset).
    $callparam["Async"] = true;
    # Cloudvox settings
    $cloudvox["username"] = 'manager';
    $cloudvox["password"] = 'PASSWORD';
    $cloudvox["server"] = 'SOMETHING.cloudvox.com:PORT';
    $asm = new AGI_AsteriskManager();
    if ($asm->connect($cloudvox["server"], $cloudvox["username"], $cloudvox["password"])) {
      foreach(explode(',', $argv[1]) as $call) {
        # Number to call, prefaced by 1+areacode (just like your home phone).
        # Format: Local/[email protected]
        $callparam["Channel"] = "Local/${call}@outgoing-X";
        # Let's do this thing. Place the call.
        $res = $asm->send_request("Originate", $callparam);
        # Print each message received when the outgoing call was queued or made.
        foreach ($res as $r) {
          if ($r == "Success") {
            echo "Sucessfully originated call: $r\n";
          } else {
            echo "Event: $r\n";
      print "all done.\n";
    } else {
      echo 'Could not connect to phone server.';
    #!/usr/bin/php -q
    # Handle call from users/customers and play them the status recording
    # (made by admin in nagios-answer.php). Could use database or other PHP
    # to validate PIN, choose message, route them to human SIP or PSTN operator, etc.
    $agi = new AGI();
    $agi->exec('Swift', "\"Thank you for calling OurCo's system status. Please enter your 5-digit access code.\"");
    $agi->exec('Read', 'pin||5||2|15');
    $pin = $agi->get_variable('pin');
    if ($pin['data'] == '12345') {
      $agi->exec('Swift', "\"Here is the latest system status.\"");
      $res = $agi->exec('Playback', 'outage_alert');
      if ($res['result'] != '0') {
        # alert file not found
        $agi->exec('Swift', "\"All systems are online.\"");
    } else {
      $agi->exec('Swift', "\"Sorry, that was not a valid access code. Goodbye.\"");
    #!/usr/bin/php -q
    # Handle a call and let the other end record a spoken message.
    $agi = new AGI();
    $hostname = $agi->get_variable('hostname');
    $hoststate = $agi->get_variable('hoststate');
    $agi->exec('Swift', "\"This is Nagios Bot. ${hostname['data']} is now ${hoststate['data']}. Press 1 to record an outage message.\"");
    $agi->exec('Read', 'user_choice||1||2|15');
    $user_choice = $agi->get_variable('user_choice');
    if ($user_choice['data'] == '1') {
      $agi->exec('Swift', "\"Now recording a new outage alert\"");
      # up to 6 seconds of silence, 60 seconds total
      $agi->exec('Record', "outage_alert.wav|6|60");
      $agi->exec('Swift', "\"We've saved the following outage message\"");
      $agi->exec('Playback', 'outage_alert');
    } else {
      $agi->exec('Swift', "\"You entered something unexpected -- it was ${user_choice['data']}.\"");
    Was this page helpful?
    標籤 (Edit tags)
    • No tags
    您必須 登入 才能發佈評論。
    Powered by MindTouch Core