root/src/java/src/com/omniti/reconnoiter/event/NoitBundlev2.java

Revision e8b241b833cdda315cc463b322a89ba888c5e781, 4.2 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 5 years ago)

juggle files around for cleaner builds.

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2011, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  * The software in this package is published under the terms of the GPL license
5  * a copy of which can be found at:
6  * https://labs.omniti.com/reconnoiter/trunk/src/java/LICENSE
7  */
8
9 package com.omniti.reconnoiter.event;
10
11 import java.util.LinkedList;
12 import com.omniti.reconnoiter.IEventHandler;
13 import com.omniti.reconnoiter.event.NoitEvent;
14 import com.omniti.reconnoiter.event.NoitStatus;
15 import com.omniti.reconnoiter.event.NoitMetric;
16 import com.omniti.reconnoiter.CheckStatus;
17 import org.apache.commons.codec.binary.Base64;
18
19 public class NoitBundlev2 extends NoitEvent {
20   LinkedList<NoitEvent> items;
21   private long time;
22   private String noit;
23   private String uuid;
24   private String check_target;
25   private String check_module;
26   private String check_name;
27
28   public String getPrefix() {
29     return "B2";
30   }
31
32   protected byte[] decompress(byte input[], int len) {
33     return input;
34   }
35   protected byte[] unwrap(String input, int len) {
36     return decompress(Base64.decodeBase64(input), len);
37   }
38   protected CheckStatus.Bundle decode(String input, int len) {
39     try {
40       return CheckStatus.Bundle.parseFrom(unwrap(input, len));
41     } catch(com.google.protobuf.InvalidProtocolBufferException e) {
42     }
43     return null;
44   }
45   /*
46    'B#' REMOTE TIMESTAMP UUID TARGET MODULE NAME RAWLEN ENCODED
47    */
48   public NoitBundlev2() {}
49   public NoitBundlev2(String[] parts) throws Exception {
50     super(parts);
51     items = new LinkedList<NoitEvent>();
52     String id[] = extended_id_split(parts[3]);
53     noit = parts[1];
54     String timestamp = parts[2];
55     time = timeToLong(timestamp);
56     check_target = id[0];
57     check_module = id[1];
58     check_name = id[2];
59     uuid = id[3];
60     String target = parts[4];
61     String module = parts[5];
62     String name = parts[6];
63     int rawlen = Integer.parseInt(parts[7]);
64     CheckStatus.Bundle bundle = decode(parts[8], rawlen);
65     if(bundle != null) {
66       CheckStatus.Status status = bundle.getStatus();
67       if(status != null) {
68         char state[] = new char [] { (char)status.getState() };
69         char available[] = new char [] { (char) status.getAvailable() };
70
71         items.addLast(new NoitStatus(new java.lang.String[]
72                       { "S", noit, timestamp, parts[3], new String(state),
73                         new String(available),
74                         new Integer(status.getDuration()).toString(),
75                         status.getStatus() }));
76       }
77       for(CheckStatus.Metric metric : bundle.getMetricsList()) {
78         char metrictype[] = new char [] { (char)metric.getMetricType() };
79         String v_str = null;
80         switch(metrictype[0]) {
81           case 'i':
82             if(metric.hasValueI32())
83               v_str = Integer.toString(metric.getValueI32());
84             break;
85           case 'I':
86             if(metric.hasValueUI32())
87               v_str = Long.toString(metric.getValueUI32());
88             break;
89           case 'l':
90             if(metric.hasValueI64())
91               v_str = Long.toString(metric.getValueI64());
92             break;
93           case 'L':
94             if(metric.hasValueUI64())
95               v_str = Double.toString(metric.getValueUI64());
96             break;
97           case 'n':
98             if(metric.hasValueDbl())
99               v_str = Double.toString(metric.getValueDbl());
100             break;
101           case 's': v_str = metric.getValueStr();
102           default:
103             break;
104         }
105         if(v_str == null) v_str = "[[null]]";
106         items.addLast(new NoitMetric(new java.lang.String[]
107                       { "M", noit, timestamp, parts[3], metric.getName(),
108                         new String(metrictype), v_str }));
109       }
110     }
111   }
112
113   public String getUuid() { return uuid; }
114   public long getTime() { return time; }
115   public String getNoit() { return noit; }
116   public String getCheck_target() { return check_target; }
117   public String getCheck_module() { return check_module; }
118   public String getCheck_name() { return check_name; }
119
120   public int numparts() { return 9; }
121   public void handle(IEventHandler eh) {
122     for(NoitEvent e : items) {
123       if (eh.stopProcessing(e, getPrefix()) == false)
124         e.handle(eh);
125     }
126   }
127 }
Note: See TracBrowser for help on using the browser.