1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package it.jnrpe.plugin.jmx;
17
18 import it.jnrpe.ICommandLine;
19 import it.jnrpe.ReturnValue;
20 import it.jnrpe.Status;
21 import it.jnrpe.events.LogEvent;
22 import it.jnrpe.plugins.IPluginInterface;
23
24 import java.io.ByteArrayOutputStream;
25 import java.io.IOException;
26 import java.io.PrintStream;
27
28
29
30
31
32
33 public class CCheckJMX extends JMXQuery implements IPluginInterface {
34
35
36
37
38
39
40
41
42 public final ReturnValue execute(final ICommandLine cl) {
43 if (cl.hasOption('U')) {
44 setUrl(cl.getOptionValue('U'));
45 }
46 if (cl.hasOption('O')) {
47 setObject(cl.getOptionValue('O'));
48 }
49 if (cl.hasOption('A')) {
50 setAttribute(cl.getOptionValue('A'));
51 }
52 if (cl.hasOption('I')) {
53 setInfo_attribute(cl.getOptionValue('I'));
54 }
55 if (cl.hasOption('J')) {
56 setInfo_key(cl.getOptionValue('J'));
57 }
58 if (cl.hasOption('K')) {
59 setAttribute_key(cl.getOptionValue('K'));
60 }
61 if (cl.hasOption('w')) {
62 setWarning(cl.getOptionValue('w'));
63 }
64 if (cl.hasOption('c')) {
65 setCritical(cl.getOptionValue('c'));
66 }
67 if (cl.hasOption("username")) {
68 setUsername(cl.getOptionValue("username"));
69 }
70 if (cl.hasOption("password")) {
71 setPassword(cl.getOptionValue("password"));
72 }
73
74 setVerbatim(2);
75
76
77 try {
78 connect();
79 execute();
80 ByteArrayOutputStream bout = new ByteArrayOutputStream();
81 PrintStream ps = new PrintStream(bout);
82 Status status = report(ps);
83 ps.flush();
84 ps.close();
85 return new ReturnValue(status, new String(bout.toByteArray()));
86 } catch (Exception ex) {
87 log.warn("An error has occurred during execution "
88 + "of the CHECK_JMX plugin : "
89 + ex.getMessage(), ex);
90 ByteArrayOutputStream bout = new ByteArrayOutputStream();
91 PrintStream ps = new PrintStream(bout);
92 Status status = report(ex, ps);
93 ps.flush();
94 ps.close();
95 return new ReturnValue(status, new String(bout.toByteArray()));
96 } finally {
97 try {
98 disconnect();
99 } catch (IOException e) {
100 log.warn("An error has occurred during execution"
101 + " of the CHECK_JMX plugin : "
102 + e.getMessage(), e);
103 ByteArrayOutputStream bout = new ByteArrayOutputStream();
104 PrintStream ps = new PrintStream(bout);
105
106 Status status = report(e, ps);
107 ps.flush();
108 ps.close();
109 return new ReturnValue(status, new String(bout.toByteArray()));
110 }
111 }
112 }
113
114 @Override
115 protected String getPluginName() {
116 return "CHECK_JMX";
117 }
118 }