AXP(Application eXtension Platform)/IOS Event API

バージョン 2

    AXP(Application eXtension Platform)へ戻る

     

    IOS Event API を使うことで、AXP OSまたは、AXP UDL の仮想インスタンスから、IOSのイベントを監視することができます。

    IOS Event APIの設定には、EEM(Embedded Event Manager)に関する知識が必要です。詳細については、各種Ciscoドキュメントを参照してください。

    依存ファイル

    IOS Event APIを使うためには、axpsystemapi を依存関係として指定する必要があります。

    Name: eventapi (1.6.1)
    Desc: IOS Event API
        id: 545c3671-c4bc-43b8-bce4-690123ab9d4d
    Type: (application)

     

    IOS Event APIを使用すると、ルータ上では、以下のようにEEMポリシーを確認することができます。
    ※以下の例は、pythonのサンプルを実行中に表示した例

    AXP#show event manager policy registered
    No.  Class     Type    Event Type          Trap  Time Registered           Name
    Client Policies
    No.  Class     Type    Event Type          Trap  Time Registered           Name
    1    axp       user    timer watchdog      Off   Tue Oct 12 17:18:34 2010  PYTHON_28_TIMER
    name {wdtimer1} time 5.000
    queue-priority normal maxrun 600.000

    2    axp       user    interface           Off   Tue Oct 12 17:18:34 2010  PYTHON_28_INTERFACE
    name {gi0/1} parameter {receive_broadcasts} entry_op gt entry_val 1 entry_type value
    queue-priority normal maxrun 600.000

    3    axp       user    syslog              Off   Tue Oct 12 17:18:34 2010  PYTHON_28_SYSLOG
    pattern {down}
    queue-priority normal maxrun 600.000

     

     

    Pythonの場合

     

    1. IOSEvent.pyを作成します。
      #!/bin/env python
      # ---------------------------------------------------------------------
      # Register events
      # ---------------------------------------------------------------------
      import __builtin__
      import sys
      import time
      sys.path.append('/usr/lib/python2.4/serviceapi')
      sys.path.append('/usr/lib/python2.4/serviceapi/eventapi/')
      sys.path.append("/usr/lib/python2.4/iosapi")
      from AppreAPI import *
      import AxpEventAPI
      import NotifyRequest
      import PolicyInfo
      import ParamList
      import Notification
      import ConfigChange
      import ErrorInfo
      import EventHandler
      import IosapiFactory
      import Iosapi
      # -------------------------------------------------------------
      # Setup callback procedure for the event handler.
      # -------------------------------------------------------------
      class DTEEM_EventHandler(EventHandler.EventHandler):
           def callback(self, notification):
               if (notification != None):
                   print "Event got triggered on ", notification.getEventTime()
                   #print notification.toString()

      # ----------------------------------------------
      # Register config change event.
      # ----------------------------------------------
      iosRequest = AxpEventAPI.getNotifyRequest("IOS")
      eventCallback = DTEEM_EventHandler()
      policy1 = PolicyInfo.PolicyInfo("PYTHON_28_CONFIG", "config-change", None)
      eventHandle_config = iosRequest.register(policy1, eventCallback)
      # ----------------------------------------------
      # Register Timer event.
      # ----------------------------------------------
      policy2 = PolicyInfo.PolicyInfo("PYTHON_28_TIMER", "EEM", "timer")
      params_2 = policy2.getPolicyParams()
      params_2.setParam("watchdog", None)
      params_2.setParam("name", "wdtimer1")
      params_2.setParam("sec", "5")
      eventHandle_timer = iosRequest.register(policy2, eventCallback)
      # ----------------------------------------------
      # Register Interface event.
      # ----------------------------------------------
      policy3 = PolicyInfo.PolicyInfo("PYTHON_28_INTERFACE", "EEM", "interface")
      params_3 = policy3.getPolicyParams()
      params_3.setParam("name", "gi0/0")
      params_3.setParam("parameter", "receive_broadcasts")
      params_3.setParam("entry_op", "ge")
      params_3.setParam("entry_val", "1")
      params_3.setParam("entry_val_is_increment", "FALSE")
      eventHandle_interface = iosRequest.register(policy3, eventCallback)
      # ----------------------------------------------
      # Register Syslog event.
      # ----------------------------------------------
      policy4 = PolicyInfo.PolicyInfo("PYTHON_28_SYSLOG", "EEM", "syslog")
      params_4 = policy4.getPolicyParams()
      params_4.setParam("pattern", "down")
      eventHandle_syslog = iosRequest.register(policy4, eventCallback)
      # -------------------------------------------------------------------
      # Show the event counters.
      # -------------------------------------------------------------------
      time.sleep(20)
      api=AppreAPI()
      cmd = "show event counter"
      status, response = api.Exec(cmd)
      print response
      # ----------------------------------------------
      # Unregister the event.
      # ----------------------------------------------
      iosRequest.deregister(eventHandle_config)
      iosRequest.deregister(eventHandle_timer)
      iosRequest.deregister(eventHandle_interface)
      iosRequest.deregister(eventHandle_syslog)
    2. SystemOpExample.py をパッケージに含めてAXPにインストールします。(rsync,scpなどでコピーしてもよいです)
      ※pythonをRPMでインストールすることを忘れないでください。
    3. 実行します。
      bash-3.2# ./IOSEvent.py

     

     

    Javaの場合

     

    1. IOSEventExample.javaを作成します。
      // ---------------------------------------------------------------------
      // Register events
      // ---------------------------------------------------------------------
      import com.cisco.aesop.apphosting.iosapi.*;
      import com.cisco.aesop.apphosting.appreapi.*;
      import com.cisco.aesop.apphosting.serviceapi.*;
      import com.cisco.aesop.apphosting.serviceapi.eventapi.*;
      public class IOSEventExample implements EventHandler {
           public void callback(Notification notification) {
               System.out.println("Event triggered on " + notification.getEventTime());
           }
           public static void main(String args[]) {
               // --------------------------------------------------
               // Register timer event.
               // --------------------------------------------------
               AxpEventAPI axpApi = new AxpEventAPI();
               NotifyRequest iosRequest = axpApi.getNotifyRequest("ios");
               String eventHandle_timer = "";
               IOSEventExample eventCallback = new IOSEventExample();
               try {
                   PolicyInfo policy = new PolicyInfo("JAVA_41_TIMER", "EEM", "timer");
                   ParamList params = policy.getPolicyParams();
                   params.setParam("watchdog", null);
                   params.setParam("name", "wdtimer1");
                   params.setParam("sec", "5");
                   eventHandle_timer = iosRequest.register(policy, eventCallback);
               } catch (ErrorInfo ei) {
                   System.out.println(ei.getErrorCode() + " " + ei.getErrorMessage());
               }
               // -------------------------------------------------------------------
               // Register interface event.
               // -------------------------------------------------------------------
               String eventHandle_interface = "";
               try {
                   PolicyInfo policy = new PolicyInfo("JAVA_41_INTERFACE", "EEM", "interface");
                   ParamList params = policy.getPolicyParams();
                   params.setParam("name", "eth0/0");
                   params.setParam("parameter", "receive_broadcasts");
                   params.setParam("entry_op", "gt");
                   params.setParam("entry_val", "1");
                   params.setParam("entry_val_is_increment", "FALSE");
                   eventHandle_interface = iosRequest.register(policy, eventCallback);
               } catch (ErrorInfo ei) {
                   System.out.println(ei.getErrorCode() + " " + ei.getErrorMessage());
               }
               // --------------------------------------------------
               // Register syslog event.
               // --------------------------------------------------
               String eventHandle_syslog = "";
               try {
                   PolicyInfo policy = new PolicyInfo("JAVA_41_SYSLOG", "EEM", "syslog");
                   ParamList params = policy.getPolicyParams();
                   params.setParam("pattern", "down");
                   eventHandle_syslog = iosRequest.register(policy, eventCallback);
               } catch (ErrorInfo ei) {
                   System.out.println(ei.getErrorCode() + " " + ei.getErrorMessage());
               }
               // --------------------------------------------------
               // Register config change event.
               // --------------------------------------------------
               String eventHandle_config = "";
               try {
                   PolicyInfo policy = new PolicyInfo("JAVA_41_CONFIG", "config-change", null);
                   eventHandle_config = iosRequest.register(policy, eventCallback);
               } catch (ErrorInfo ei) {
                   System.out.println(ei.getErrorCode() + " " + ei.getErrorMessage());
               }
               // --------------------------------------------------
               // Show event counts.
               // --------------------------------------------------
               try {
                   Thread.sleep(10000);
                   CommonServiceImpl apiCall = new CommonServiceImpl();
                   AppreMessage msg = new AppreMessage();
                   String cmd = "show event counter";
                   msg.setRequest(cmd);
                   apiCall.exec(msg);
                   System.out.println(msg.getResponse());
               } catch (Exception e) {
                   System.out.println(e);
               }
               // --------------------------------------------------
               // Unregister events.
               // --------------------------------------------------
               try {
                   iosRequest.deregister(eventHandle_timer);
                   iosRequest.deregister(eventHandle_config);
                   iosRequest.deregister(eventHandle_interface);
                   iosRequest.deregister(eventHandle_syslog);
               } catch (ErrorInfo ei) {
                   System.out.println(ei.getErrorCode() + " " + ei.getErrorMessage());
               }
           }
      }
    2. コンパイルします。
      [sample]$ javac -cp /opt/axp/sdk/jar/iosapi.jar:/opt/axp/sdk/jar/appreapi.jar:/opt/axp/sdk/jar/eventapi.jar IOSEventExample.java
    3. SystemOpExample.class をパッケージに含めてAXPにインストールします。(rsync,scpなどでコピーしてもよいです)
      ※jreをRPMでインストールすることを忘れないでください。
    4. 実行します。
      bash-3.2 $ java -cp /usr/lib/java/iosapi.jar:/usr/lib/java/appreapi.jar:/usr/lib/java/eventapi.jar:/usr/lib/java/xercesImpl.jar:. IOSEventExample

     

     

     

    Cの場合

     

    1. ソースコードおよびMakefileを作成します。
      // ---------------------------------------------------------------------
      // Register events
      // ---------------------------------------------------------------------
      #include <stdio.h>
      #include <stdlib.h>
      #include <string.h>
      #include <iosapi.h>
      #include <appreapi.h>
      #include <AxpServiceAPI.h>
      void eventCallback(Notification *notification) {
           printf("Event triggered on %s\n", notification->getEventTime(notification));
      }
      int main()
      {
           static NotifyRequest *iosRequest = NULL;
           ErrorInfo err;
           ParamList *evtParam;
           // ------------------------------------
           // Register timer event.
           // ------------------------------------
           getNotifyRequest("ios", &iosRequest);
           PolicyInfo* policy_timer = PolicyInfo_new("C_41_TIMER", "EEM", "timer");
           evtParam = policy_timer->getPolicyParams(policy_timer);
           evtParam->setParam(evtParam, "watchdog", NULL);
           evtParam->setParam(evtParam, "name", "wdtimer1");
           evtParam->setParam(evtParam, "sec", "5");
           int ret = iosRequest->registers(iosRequest, policy_timer, &err, &eventCallback);
           char* eventHandle_timer = policy_timer->getEventHandle(policy_timer);
           // ------------------------------------
           // Register interface event.
           // ------------------------------------
           PolicyInfo* policy_interface = PolicyInfo_new("C_41_INTERFACE", "EEM", "interface");
           evtParam = policy_interface->getPolicyParams(policy_interface);
           evtParam->setParam(evtParam, "name", "eth0/0");
           evtParam->setParam(evtParam, "parameter", "receive_broadcasts");
           evtParam->setParam(evtParam, "entry_op", "gt");
           evtParam->setParam(evtParam, "entry_val", "0");
           evtParam->setParam(evtParam, "entry_val_is_increment", "FALSE");
           ret = iosRequest->registers(iosRequest, policy_interface, &err, &eventCallback);
           char* eventHandle_interface = policy_interface->getEventHandle(policy_interface);
           // ------------------------------------
           // Register syslog event.
           // ------------------------------------
           PolicyInfo* policy_syslog = PolicyInfo_new("C_41_SYSLOG", "EEM", "syslog");
           char paramValue[] = "\"PARSER-6-EXPOSEDLOCKRELEASED\"";
           evtParam = policy_syslog->getPolicyParams(policy_syslog);
           evtParam->setParam(evtParam, "pattern", paramValue);
           ret = iosRequest->registers(iosRequest, policy_syslog, &err, &eventCallback);
           char* eventHandle_syslog = policy_syslog->getEventHandle(policy_syslog);
           // ------------------------------------
           // Register config change event.
           // ------------------------------------
           PolicyInfo* policy_config = PolicyInfo_new("C_41_CONFIG", "config-change", NULL);
           ret = iosRequest->registers(iosRequest, policy_config, &err, &eventCallback);
           char* eventHandle_config = policy_config->getEventHandle(policy_config);
           // ----------------------------------------------------------
           // Show event counts.
           // ----------------------------------------------------------
           sleep(10);
           AppreMessage_t msg;
           msg.size = 0;
           msg.response = NULL;
           char show_counter_cmd[] = "show event counter";
           msg.request = show_counter_cmd;
           appreapi_exec(&msg);
           printf("%s",msg.response);
           // ------------------------------------
           // Unregister events.
           // ------------------------------------
           iosRequest->deregister(iosRequest, eventHandle_timer, &err);
           iosRequest->deregister(iosRequest, eventHandle_interface, &err);
           iosRequest->deregister(iosRequest, eventHandle_syslog, &err);
           iosRequest->deregister(iosRequest, eventHandle_config, &err);
           exit(0);
      }
      IOSEventExample.cの例
      Makefileの例
      AXPDIR = /opt/AXP/sdk
      LIBDIR = $(AXPDIR)/lib
      INCDIR = $(AXPDIR)/include

      LDFLAGS = -L$(LIBDIR) -ldl -lc -lpthread -leventapi -lxerces-c  -lappreapi

      CC = $(PREFIX)gcc
      LD = $(CC)
      CFLAGS = $(CMODE) -Wall -I$(INCDIR) -O0 -g3

      OBJECTS = IOSEventExample.o

      %.o: %.c
                $(CC) $(CFLAGS) -c $< -o $@

      IOSEventExample: IOSEventExample.o
                $(LD) -o IOSEventExample IOSEventExample.o $(LDFLAGS)

      clean:
                rm -f *.o IOSEventExample
    2. コンパイルします
    3. IOSEventExample をパッケージに含めてAXPにインストールします。(rsync,scpなどでコピーしてもよいです)
    4. 実行します。
      bash-3.2# ./IOSEventExample