View Javadoc

1   /**
2    * This file is part of GoldenGate Project (named also GoldenGate or GG).
3    * 
4    * Copyright 2009, Frederic Bregier, and individual contributors by the @author
5    * tags. See the COPYRIGHT.txt in the distribution for a full listing of
6    * individual contributors.
7    * 
8    * All GoldenGate Project is free software: you can redistribute it and/or
9    * modify it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation, either version 3 of the License, or (at your
11   * option) any later version.
12   * 
13   * GoldenGate is distributed in the hope that it will be useful, but WITHOUT ANY
14   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15   * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Public License along with
18   * GoldenGate . If not, see <http://www.gnu.org/licenses/>.
19   */
20  package goldengate.snmp.test;
21  
22  import goldengate.common.logging.GgInternalLogger;
23  import goldengate.common.logging.GgInternalLoggerFactory;
24  import goldengate.snmp.r66.GgPrivateMib;
25  import goldengate.snmp.utils.GgMOScalar;
26  
27  import org.snmp4j.agent.DuplicateRegistrationException;
28  import org.snmp4j.agent.MOScope;
29  import org.snmp4j.smi.Counter64;
30  import org.snmp4j.smi.OID;
31  import org.snmp4j.smi.OctetString;
32  import org.snmp4j.smi.VariableBinding;
33  
34  /**
35   * Example of Implementation of GgPrivateMib
36   * 
37   * @author Frederic Bregier
38   * 
39   */
40  public class GgImplPrivateMib extends GgPrivateMib {
41      /**
42       * Internal Logger
43       */
44      private static GgInternalLogger logger = GgInternalLoggerFactory
45              .getLogger(GgImplPrivateMib.class);
46  
47      /**
48       * @param sysdesc
49       * @param port
50       * @param smiPrivateCodeFinal
51       * @param typeGoldenGateObject
52       * @param scontactName
53       * @param stextualName
54       * @param saddress
55       * @param iservice
56       */
57      public GgImplPrivateMib(String sysdesc, int port, int smiPrivateCodeFinal,
58              int typeGoldenGateObject, String scontactName, String stextualName,
59              String saddress, int iservice) {
60          super(sysdesc, port, smiPrivateCodeFinal, typeGoldenGateObject,
61                  scontactName, stextualName, saddress, iservice);
62      }
63  
64      /*
65       * (non-Javadoc)
66       * 
67       * @see goldengate.snmp.GgInterfaceMib#updateServices()
68       */
69      @Override
70      public void updateServices(GgMOScalar scalar) {
71          // 3 groups to check
72          OID oid = scalar.getOid();
73          if (oid.startsWith(rootOIDGoldenGateGlobal)) {
74              // UpTime
75              if (oid.equals(rootOIDGoldenGateGlobalUptime)) {
76                  return;
77              }
78              ((GgPrivateMonitor) agent.monitor).generalValuesUpdate();
79          } else if (oid.startsWith(rootOIDGoldenGateDetailed)) {
80              ((GgPrivateMonitor) agent.monitor).detailedValuesUpdate();
81          } else if (oid.startsWith(rootOIDGoldenGateError)) {
82              ((GgPrivateMonitor) agent.monitor).errorValuesUpdate();
83          }
84      }
85  
86      /*
87       * (non-Javadoc)
88       * 
89       * @see
90       * goldengate.snmp.GgInterfaceMib#updateServices(org.snmp4j.agent.MOScope)
91       */
92      @Override
93      public void updateServices(MOScope range) {
94          // UpTime first
95          OID low = range.getLowerBound();
96  
97          boolean okGeneral = true;
98          boolean okDetailed = true;
99          boolean okError = true;
100         if (low != null) {
101             logger.debug("low: {}:{} " + rootOIDGoldenGateGlobal + ":" +
102                     rootOIDGoldenGateDetailed + ":" + rootOIDGoldenGateError,
103                     low, range.isLowerIncluded());
104             if (low.size() <= rootOIDGoldenGate.size() &&
105                     low.startsWith(rootOIDGoldenGate)) {
106                 // test for global requests
107                 okGeneral = okDetailed = okError = true;
108             } else {
109                 // Test for sub requests
110                 okGeneral &= low.startsWith(rootOIDGoldenGateGlobal);
111                 okDetailed &= low.startsWith(rootOIDGoldenGateDetailed);
112                 okError &= low.startsWith(rootOIDGoldenGateError);
113             }
114         }
115         logger.debug("General:" + okGeneral + " Detailed:" + okDetailed +
116                 " Error:" + okError);
117         if (okGeneral) {
118             ((GgPrivateMonitor) agent.monitor).generalValuesUpdate();
119         }
120         if (okDetailed) {
121             ((GgPrivateMonitor) agent.monitor).detailedValuesUpdate();
122         }
123         if (okError) {
124             ((GgPrivateMonitor) agent.monitor).errorValuesUpdate();
125         }
126     }
127 
128     /*
129      * (non-Javadoc)
130      * 
131      * @see goldengate.snmp.GgPrivateMib#agentRegisterGoldenGateMib()
132      */
133     @Override
134     protected void agentRegisterGoldenGateMib()
135             throws DuplicateRegistrationException {
136         defaultAgentRegisterGoldenGateMib();
137     }
138 
139     /**
140      * Example of trap for All
141      * 
142      * @param message
143      * @param message2
144      * @param number
145      */
146     public void notifyInfo(String message, String message2, int number) {
147         if (!TrapLevel.All.isLevelValid(agent.trapLevel)) return;
148         logger.warn("Notify: " + NotificationElements.InfoTask + ":" + message +
149                 ":" + number);
150         agent.getNotificationOriginator().notify(
151                 new OctetString("public"),
152                 NotificationElements.InfoTask.getOID(rootOIDGoldenGateNotif),
153                 new VariableBinding[] {
154                         new VariableBinding(NotificationElements.InfoTask
155                                 .getOID(rootOIDGoldenGateNotif,
156                                         NotificationTasks.stepStatusInfo
157                                                 .getOID()), new OctetString(
158                                 message)),
159                         new VariableBinding(
160                                 NotificationElements.InfoTask
161                                         .getOID(rootOIDGoldenGateNotif,
162                                                 NotificationTasks.filenameInfo
163                                                         .getOID()),
164                                 new OctetString(message2)),
165                         new VariableBinding(NotificationElements.InfoTask
166                                 .getOID(rootOIDGoldenGateNotif,
167                                         NotificationTasks.specialIdInfo
168                                                 .getOID()), new Counter64(
169                                 number)),
170                         new VariableBinding(NotificationElements.InfoTask
171                                 .getOID(rootOIDGoldenGateNotif,
172                                         NotificationTasks.idRuleInfo.getOID()),
173                                 new OctetString(NotificationElements.InfoTask
174                                         .name())) });
175     }
176 
177     /**
178      * Example of trap for Error
179      * 
180      * @param message
181      * @param message2
182      * @param number
183      */
184     public void notifyError(String message, String message2, int number) {
185         if (!TrapLevel.Alert.isLevelValid(agent.trapLevel)) return;
186         logger.warn("Notify: " + NotificationElements.TrapError + ":" +
187                 message + ":" + number);
188         agent.getNotificationOriginator().notify(
189                 new OctetString("public"),
190                 NotificationElements.TrapError.getOID(rootOIDGoldenGateNotif),
191                 new VariableBinding[] {
192                         new VariableBinding(NotificationElements.TrapError
193                                 .getOID(rootOIDGoldenGateNotif, 1),
194                                 new OctetString(message)),
195                         new VariableBinding(NotificationElements.TrapError
196                                 .getOID(rootOIDGoldenGateNotif, 1),
197                                 new OctetString(message2)),
198                         new VariableBinding(NotificationElements.TrapError
199                                 .getOID(rootOIDGoldenGateNotif, 1),
200                                 new Counter64(number)),
201                         new VariableBinding(NotificationElements.TrapError
202                                 .getOID(rootOIDGoldenGateNotif, 1),
203                                 new OctetString(NotificationElements.TrapError
204                                         .name())) });
205     }
206 }