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 
10     by the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12  
13     GoldenGate is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17  
18     You should have received a copy of the GNU General Public License
19     along with GoldenGate .  If not, see <http://www.gnu.org/licenses/>.
20   */
21  package openr66.protocol.snmp;
22  
23  import openr66.database.data.DbTaskRunner;
24  import openr66.protocol.configuration.Configuration;
25  import openr66.protocol.localhandler.packet.RequestPacket.TRANSFERMODE;
26  import openr66.protocol.utils.Version;
27  
28  import org.snmp4j.agent.DuplicateRegistrationException;
29  import org.snmp4j.agent.MOScope;
30  import org.snmp4j.mp.SnmpConstants;
31  import org.snmp4j.smi.Gauge32;
32  import org.snmp4j.smi.OctetString;
33  import org.snmp4j.smi.TimeTicks;
34  import org.snmp4j.smi.VariableBinding;
35  
36  import goldengate.common.logging.GgInternalLogger;
37  import goldengate.common.logging.GgInternalLoggerFactory;
38  import goldengate.snmp.r66.GgPrivateMib;
39  import goldengate.snmp.utils.GgMORow;
40  import goldengate.snmp.utils.GgMOScalar;
41  import goldengate.snmp.utils.GgUptime;
42  import goldengate.snmp.utils.MemoryGauge32;
43  import goldengate.snmp.utils.MemoryGauge32.MemoryType;
44  
45  /**
46   * GoldenGate OpenR66 Private MIB implementation
47   * 
48   * @author Frederic Bregier
49   *
50   */
51  public class R66PrivateMib extends GgPrivateMib {
52      /**
53       * Internal Logger
54       */
55      private static GgInternalLogger logger = GgInternalLoggerFactory
56              .getLogger(R66PrivateMib.class);
57  
58      /**
59       * @param sysdesc
60       * @param port
61       * @param smiPrivateCodeFinal
62       * @param typeGoldenGateObject
63       * @param scontactName
64       * @param stextualName
65       * @param saddress
66       * @param iservice
67       */
68      public R66PrivateMib(String sysdesc, int port, int smiPrivateCodeFinal,
69              int typeGoldenGateObject, String scontactName, String stextualName,
70              String saddress, int iservice) {
71          super(sysdesc, port, smiPrivateCodeFinal, typeGoldenGateObject,
72                  scontactName, stextualName, saddress, iservice);
73      }
74      
75      /* (non-Javadoc)
76       * @see goldengate.snmp.GgPrivateMib#agentRegisterGoldenGateMib()
77       */
78      @Override
79      protected void agentRegisterGoldenGateMib()
80              throws DuplicateRegistrationException {
81          logger.debug("registerGGMib");
82          // register Static info
83          rowInfo = new GgMORow(this, rootOIDGoldenGateInfo, goldenGateDefinition, 
84                  MibLevel.staticInfo.ordinal());
85          rowInfo.setValue(goldenGateDefinitionIndex.applName.ordinal(), 
86                  "GoldenGate OpenR66");
87          rowInfo.setValue(goldenGateDefinitionIndex.applServerName.ordinal(), 
88                  Configuration.configuration.HOST_ID);
89          rowInfo.setValue(goldenGateDefinitionIndex.applVersion.ordinal(), 
90                  Version.ID);
91          rowInfo.setValue(goldenGateDefinitionIndex.applDescription.ordinal(), 
92                  "GoldenGate OpenR66: File Transfer Monitor");
93          rowInfo.setValue(goldenGateDefinitionIndex.applURL.ordinal(), 
94                  "http://openr66.free.fr");
95          rowInfo.setValue(goldenGateDefinitionIndex.applApplicationProtocol.ordinal(), 
96                  applicationProtocol);
97          
98          rowInfo.registerMOs(agent.getServer(), null);
99          // register General info
100         rowGlobal = new GgMORow(this, rootOIDGoldenGateGlobal, goldenGateGlobalValues, 
101                 MibLevel.globalInfo.ordinal());
102         GgMOScalar memoryScalar = rowGlobal.row[goldenGateGlobalValuesIndex.memoryTotal.ordinal()];
103         memoryScalar.setValue(new MemoryGauge32(MemoryType.TotalMemory));
104         memoryScalar = rowGlobal.row[goldenGateGlobalValuesIndex.memoryFree.ordinal()];
105         memoryScalar.setValue(new MemoryGauge32(MemoryType.FreeMemory));
106         memoryScalar = rowGlobal.row[goldenGateGlobalValuesIndex.memoryUsed.ordinal()];
107         memoryScalar.setValue(new MemoryGauge32(MemoryType.UsedMemory));
108         rowGlobal.registerMOs(agent.getServer(), null);
109         // setup UpTime to SysUpTime and change status
110         scalarUptime = rowGlobal.row[goldenGateGlobalValuesIndex.applUptime.ordinal()];
111         scalarUptime.setValue(new GgUptime(upTime));
112         changeStatus(OperStatus.restarting);
113         changeStatus(OperStatus.up);
114         // register Detailed info
115         rowDetailed = new GgMORow(this, rootOIDGoldenGateDetailed, goldenGateDetailedValues, 
116                 MibLevel.detailedInfo.ordinal());
117         rowDetailed.registerMOs(agent.getServer(), null);
118         // register Error info
119         rowError = new GgMORow(this, rootOIDGoldenGateError, goldenGateErrorValues, 
120                 MibLevel.errorInfo.ordinal());
121         rowError.registerMOs(agent.getServer(), null);
122     }
123     /**
124      * Send a notification (trap or inform) for Shutdown event
125      * @param message
126      * @param message2
127      */
128     public void notifyStartStop(String message, String message2) {
129         if (!TrapLevel.StartStop.isLevelValid(agent.trapLevel))
130             return;
131         notify(NotificationElements.TrapShutdown, message, message2);
132     }
133     /**
134      * Send a notification (trap or inform) for Error event
135      * @param message
136      * @param message2
137      */
138     public void notifyError(String message, String message2) {
139         if (!TrapLevel.Alert.isLevelValid(agent.trapLevel))
140             return;
141         notify(NotificationElements.TrapError, message, message2);
142     }
143     /**
144      * Send a notification (trap or inform) for Server Overloaded event
145      * @param message
146      * @param message2
147      */
148     public void notifyOverloaded(String message, String message2) {
149         if (!TrapLevel.Warning.isLevelValid(agent.trapLevel))
150             return;
151         notify(NotificationElements.TrapOverloaded, message, message2);
152     }
153     /**
154      * Send a notification (trap or inform) for Warning event
155      * @param message
156      * @param message2
157      */
158     public void notifyWarning(String message, String message2) {
159         if (!TrapLevel.Warning.isLevelValid(agent.trapLevel))
160             return;
161         notify(NotificationElements.TrapWarning, message, message2);
162     }
163     /**
164      * Send a notification (trap or inform) for Warning/Error event on a single Transfer Task
165      * @param message
166      * @param runner
167      */
168     public void notifyInfoTask(String message, DbTaskRunner runner) {
169         if (!TrapLevel.All.isLevelValid(agent.trapLevel)) return;
170         if (logger.isDebugEnabled())
171             logger.debug("Notify: " + NotificationElements.InfoTask + ":" + message +
172                 ":" + runner.toShortString());
173         long delay = (runner.getStart().getTime()-
174                 agent.getUptimeSystemTime())/10;
175         if (delay <0)
176             delay = 0;
177         agent.getNotificationOriginator()
178                 .notify(new OctetString("public"),
179                         NotificationElements.InfoTask
180                                 .getOID(rootOIDGoldenGateNotif),
181                         new VariableBinding[] {
182                                 new VariableBinding(
183                                         NotificationElements.InfoTask.getOID(
184                                                 rootOIDGoldenGateNotif, 1),
185                                         new OctetString(
186                                                 NotificationElements.InfoTask
187                                                         .name())),
188                                 new VariableBinding(
189                                         NotificationElements.InfoTask.getOID(
190                                                 rootOIDGoldenGateNotif, 1),
191                                         new OctetString(message)),
192                                 // Start of Task
193                                 new VariableBinding(
194                                         NotificationElements.InfoTask
195                                                 .getOID(rootOIDGoldenGateNotif,
196                                                         NotificationTasks.globalStepInfo
197                                                                 .getOID()),
198                                         new Gauge32(runner.getGloballaststep())),
199                                 new VariableBinding(
200                                         NotificationElements.InfoTask
201                                                 .getOID(rootOIDGoldenGateNotif,
202                                                         NotificationTasks.stepInfo
203                                                                 .getOID()),
204                                         new Gauge32(runner.getStep()+1)),
205                                 new VariableBinding(
206                                         NotificationElements.InfoTask
207                                                 .getOID(rootOIDGoldenGateNotif,
208                                                         NotificationTasks.rankFileInfo
209                                                                 .getOID()),
210                                         new Gauge32(runner.getRank())),
211                                 new VariableBinding(
212                                         NotificationElements.InfoTask
213                                                 .getOID(rootOIDGoldenGateNotif,
214                                                         NotificationTasks.stepStatusInfo
215                                                                 .getOID()),
216                                         new OctetString(runner.getStatus().mesg)),
217                                 new VariableBinding(
218                                         NotificationElements.InfoTask
219                                                 .getOID(rootOIDGoldenGateNotif,
220                                                         NotificationTasks.filenameInfo
221                                                                 .getOID()),
222                                         new OctetString(runner.getFilename())),
223                                 new VariableBinding(
224                                         NotificationElements.InfoTask
225                                                 .getOID(rootOIDGoldenGateNotif,
226                                                         NotificationTasks.originalNameInfo
227                                                                 .getOID()),
228                                         new OctetString(runner.getOriginalFilename())),
229                                 new VariableBinding(
230                                         NotificationElements.InfoTask
231                                                 .getOID(rootOIDGoldenGateNotif,
232                                                         NotificationTasks.idRuleInfo
233                                                                 .getOID()),
234                                         new OctetString(runner.getRuleId())),
235                                 new VariableBinding(
236                                         NotificationElements.InfoTask
237                                                 .getOID(rootOIDGoldenGateNotif,
238                                                         NotificationTasks.modeTransInfo
239                                                                 .getOID()),
240                                         new OctetString(TRANSFERMODE.values()[runner.getMode()].name())),
241                                 new VariableBinding(
242                                         NotificationElements.InfoTask
243                                                 .getOID(rootOIDGoldenGateNotif,
244                                                         NotificationTasks.retrieveModeInfo
245                                                                 .getOID()),
246                                         new OctetString(runner.isSender()?"Sender":"Receiver")),
247                                 new VariableBinding(
248                                         NotificationElements.InfoTask
249                                                 .getOID(rootOIDGoldenGateNotif,
250                                                         NotificationTasks.startTransInfo
251                                                                 .getOID()),
252                                         new TimeTicks(delay)),
253                                 new VariableBinding(
254                                         NotificationElements.InfoTask
255                                                 .getOID(rootOIDGoldenGateNotif,
256                                                         NotificationTasks.infoStatusInfo
257                                                                 .getOID()),
258                                         new OctetString(runner.getErrorInfo().mesg)),
259                                 new VariableBinding(
260                                         NotificationElements.InfoTask
261                                                 .getOID(rootOIDGoldenGateNotif,
262                                                         NotificationTasks.requesterInfo
263                                                                 .getOID()),
264                                         new OctetString(runner.getRequester())),
265                                 new VariableBinding(
266                                         NotificationElements.InfoTask
267                                                 .getOID(rootOIDGoldenGateNotif,
268                                                         NotificationTasks.requestedInfo
269                                                                 .getOID()),
270                                         new OctetString(runner.getRequested())),
271                                 new VariableBinding(
272                                         NotificationElements.InfoTask
273                                                 .getOID(rootOIDGoldenGateNotif,
274                                                         NotificationTasks.specialIdInfo
275                                                                 .getOID()),
276                                         new OctetString(""+runner.getSpecialId())),
277                                 // End of Task
278                                 new VariableBinding(SnmpConstants.sysDescr,
279                                         snmpv2.getDescr()),
280                                 new VariableBinding(SnmpConstants.sysObjectID,
281                                         snmpv2.getObjectID()),
282                                 new VariableBinding(SnmpConstants.sysContact,
283                                         snmpv2.getContact()),
284                                 new VariableBinding(SnmpConstants.sysName,
285                                         snmpv2.getName()),
286                                 new VariableBinding(SnmpConstants.sysLocation,
287                                         snmpv2.getLocation()) });
288     }
289     /**
290      * Trap/Notification
291      * @param element
292      * @param message
293      * @param message2
294      */
295     private void notify(NotificationElements element, String message, String message2) {
296         if (logger.isDebugEnabled())
297             logger.debug("Notify: "+element+":"+message+":"+message2);
298         agent.getNotificationOriginator().notify(
299                 new OctetString("public"), 
300                 element.getOID(rootOIDGoldenGateNotif),
301                 new VariableBinding[] {
302                     new VariableBinding(
303                             element.getOID(rootOIDGoldenGateNotif, 1),
304                             new OctetString(element.name())),
305                     new VariableBinding(
306                             element.getOID(rootOIDGoldenGateNotif, 1),
307                             new OctetString(message)),
308                     new VariableBinding(
309                             element.getOID(rootOIDGoldenGateNotif, 1), 
310                             new OctetString(message2)),
311                     new VariableBinding(SnmpConstants.sysDescr, snmpv2.getDescr()),
312                     new VariableBinding(SnmpConstants.sysObjectID, snmpv2.getObjectID()),
313                     new VariableBinding(SnmpConstants.sysContact, snmpv2.getContact()),
314                     new VariableBinding(SnmpConstants.sysName, snmpv2.getName()),
315                     new VariableBinding(SnmpConstants.sysLocation, snmpv2.getLocation())
316             });
317     }    
318     /* (non-Javadoc)
319      * @see goldengate.snmp.GgInterfaceMib#updateServices(goldengate.snmp.GgMOScalar)
320      */
321     @Override
322     public void updateServices(GgMOScalar scalar) {
323     }
324 
325     /* (non-Javadoc)
326      * @see goldengate.snmp.GgInterfaceMib#updateServices(org.snmp4j.agent.MOScope)
327      */
328     @Override
329     public void updateServices(MOScope range) {
330     }
331 
332 }