アスタリスククラスター 登録情報の一元化

500人以上の従業員を抱える企業でアスタリスクベースのテレフォニーを使用しているほとんどの管理者は、遅かれ早かれ、完全なアクティブ/アクティブクラスタリングの問題を提起します。 これの前提条件は、地域支社の存在と、システムの信頼性を高めることです。 トピックは広範であり、この記事全体の目的ではありません。これは、クラスター内のサーバーにデバイスを登録することに関する情報を取得するための最速かつ最も信頼できる方法の1つを示し、その後のクラスター内での集中化および/または配布を目的として書かれたものです。 最も生産的な方法はアスタリスク自体の一部であると仮定することは論理的です。



したがって、猫が尻尾を引っ張らないようにするために、アスタリスクのロード可能モジュールのテンプレートは次のとおりです。



#include "asterisk.h" ASTERISK_FILE_VERSION(__FILE__, "$Revision: $") #include "asterisk/module.h" #include "asterisk/logger.h" static int load_module(void){ // Init code here return AST_MODULE_LOAD_SUCCESS; } static int unload_module(void){ // Destroy code here return 0; } AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hello World");
      
      





これは、resサブディレクトリのAsterisk sortsフォルダに配置する必要がある最小限のコードです。 コンパイル時に、「モジュール名として」という名前と「Hello World」という説明が付いた新しいモジュールがコンパイルされます。



さて、私たちはアスタリスクの中に入りました、次は何ですか? 電話の登録に関する情報を取得する必要があります。ボーナスとして、電話のIPアドレス、おそらくそのジッターとステータス(USE / NOT_USE / HOLD)を知りたいです。



アスタリスクでは、これに対してStasisが存在します。 残念ながら、このメカニズムがどのように機能するかを理解する唯一の方法は、ソースコードを調べることです。 したがって、3つの簡単な手順を実行します。



1.停滞バスからイベントを受信するために購読する



 stasis_subscribe(ast_endpoint_topic_all(),acl_change_stasis_dev_status,NULL);
      
      





ast_endpoint_topic_all()-「トピック」メッセージの名前を返します。

acl_change_stasis_dev_status-これは、指定したトピックから必要なメッセージがスタシスに表示されたときに呼び出される関数です。


2.必要なメッセージをキャッチする関数を作成します。

 static void acl_change_stasis_dev_status(void *data, struct stasis_subscription *sub, struct stasis_message *msg){ }
      
      





3.実際、最もおいしいのはイベント処理コードです。

自分で描く前に、あなたは理解する必要があります、そしてそれは私たちにどのような形でやってくるのですか? これを行うために、我々はその種類に登り、ここでそのような部分を見つけます:



 ast_endpoint_blob_publish(peer->endpoint, ast_endpoint_state_type(), blob);
      
      





さらに:



 void ast_endpoint_blob_publish(struct ast_endpoint *endpoint, struct stasis_message_type *type, struct ast_json *blob) { RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup); if (blob) { message = ast_endpoint_blob_create(endpoint, type, blob); } if (message) { stasis_publish(ast_endpoint_topic(endpoint), message); } } struct stasis_message *ast_endpoint_blob_create(struct ast_endpoint *endpoint, struct stasis_message_type *type, struct ast_json *blob) { RAII_VAR(struct ast_endpoint_blob *, obj, NULL, ao2_cleanup); RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup); if (!type) { return NULL; } if (!blob) { blob = ast_json_null(); } if (!(obj = ao2_alloc(sizeof(*obj), endpoint_blob_dtor))) { return NULL; } if (endpoint) { if (!(obj->snapshot = ast_endpoint_snapshot_create(endpoint))) { return NULL; } } obj->blob = ast_json_ref(blob); if (!(msg = stasis_message_create(type, obj))) { return NULL; } ao2_ref(msg, +1); return msg; }
      
      





このコードを提供するものは何ですか? これを関数のペイロードとして理解すると、ast_endpoint_blobが取得されます。この中にはast_endpoint_snapshotとJSONがあります。



今、私たちのコード:



  if(ast_endpoint_state_type() != stasis_message_type(msg))return; // ,     ? //       Asterisk      struct ast_endpoint_blob * n=stasis_message_data(msg); //          ast_endpoint_blob //      JSON struct ast_json * m; struct ast_endpoint_snapshot *snap; //        c JSON   ast_endpoint_snapshot snap=n->snapshot; //     m=n->blob; //  JSON char buffer[1050]; sprintf(buffer,"Device %s (%s): %s\n",snap->id,ast_endpoint_state_to_string(snap->state),ast_json_dump_string_format(m,AST_JSON_COMPACT)); ast_log(LOG_NOTICE,buffer); //    
      
      





上記の構造は、次の包含物を引き出します。



  #include "asterisk/stasis_endpoints.h" #include "asterisk/stasis.h" #include "asterisk/stasis_message_router.h" #include "asterisk/stasis_channels.h" #include "asterisk/stasis_bridges.h" #include "asterisk/stasis_system.h" #include "asterisk/devicestate.h" #include "asterisk/json.h"
      
      





また、モジュールを作成するときにそれらについて覚えておく必要があります。



合計:



 #include "asterisk.h" ASTERISK_FILE_VERSION(__FILE__, "$Revision: $") #include "asterisk/module.h" #include "asterisk/logger.h" #include "asterisk/stasis_endpoints.h" #include "asterisk/stasis.h" #include "asterisk/stasis_message_router.h" #include "asterisk/stasis_channels.h" #include "asterisk/stasis_bridges.h" #include "asterisk/stasis_system.h" #include "asterisk/devicestate.h" #include "asterisk/json.h" static void acl_change_stasis_dev_status(void *data, struct stasis_subscription *sub, struct stasis_message *msg){ if(ast_endpoint_state_type() != stasis_message_type(msg))return; struct ast_endpoint_blob * n=stasis_message_data(msg); struct ast_json * m; struct ast_endpoint_snapshot *snap; snap=n->snapshot; m=n->blob; char buffer[1050]; sprintf(buffer,"Device %s (%s): %s\n",snap->id,ast_endpoint_state_to_string(snap->state),ast_json_dump_string_format(m,AST_JSON_COMPACT)); ast_log(LOG_NOTICE,buffer); } static int load_module(void){ stasis_subscribe(ast_endpoint_topic_all(),acl_change_stasis_dev_status,NULL); return AST_MODULE_LOAD_SUCCESS; } static int unload_module(void){ //      return 0; }
      
      





これは何のためですか? 受信した情報は、単一のクラスターデータベースに格納できます。このデータベースは、デバイスが登録されているサーバーを常に認識しています。 ダイヤルプランツールを使用して、この情報に基づいてコールをスマッシュすることはすでに可能です。



そして、実際には、次のようになります。



画像







All Articles