modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java | 48 +++++----- modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/controller/NagiosManagementInterface.java | 13 ++ modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/network/NetworkConnection.java | 8 + modules/plugins/nagios/src/main/resources/META-INF/rhq-plugin.xml | 3 4 files changed, 47 insertions(+), 25 deletions(-)
New commits: commit 5a73a93bb971386717dd8502a8085cf78b6d2a99 Merge: 6b5ccd5... 1b03157... Author: Heiko W. Rupp hwr@redhat.com Date: Thu May 27 13:41:05 2010 +0200
Merge branch 'nagios' of ssh://git.fedorahosted.org/git/rhq/rhq into nagios
commit 6b5ccd530020cf7de394dcc6a467b5d6b38dafa6 Author: Heiko W. Rupp hwr@redhat.com Date: Thu May 27 13:36:23 2010 +0200
Refactor to get rid of code duplication.
diff --git a/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java b/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java index 9e2a663..86e692c 100644 --- a/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java +++ b/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java @@ -156,34 +156,29 @@ public class NagiosMonitorComponent implements ResourceComponent, MeasurementFac log.debug("RegEx: " + pattern); }
- if (req.getDataType() == DataType.MEASUREMENT) { - String value = nagiosSystemData.getSingleHostServiceMetric(property, serviceName, "localhost").getValue(); // TODO use 'real' host + // Get "raw" data from nagios data structures - we need to pick our value below + String value = nagiosSystemData.getSingleHostServiceMetric(property, serviceName, "localhost").getValue(); // TODO use 'real' host
- Pattern p = Pattern.compile(pattern); - Matcher m = p.matcher(value); - if (m.matches()) { - String val = m.group(1); + Pattern p = Pattern.compile(pattern); + Matcher m = p.matcher(value); + if (m.matches()) { + String val = m.group(1); // Our metric is always in the first match group.
+ // We have a match, now dispatch by dataType of the request + if (req.getDataType() == DataType.MEASUREMENT) { MeasurementDataNumeric res = new MeasurementDataNumeric(req, Double.valueOf(val)); report.addData(res); } - else { - log.warn("Pattern >>" + pattern + "<< did not match for input >>" + value + "<< and request: >>" + req.getName()); + else if(req.getDataType() == DataType.TRAIT) { + MeasurementDataTrait res = new MeasurementDataTrait(req, val); + report.addData(res); } + else + log.error("Unknown DataType for request " + req); } - else if(req.getDataType() == DataType.TRAIT) - { - String value = nagiosSystemData.getSingleHostServiceMetric(property, serviceName, "localhost").getValue(); // TODO use 'real' host - - Pattern p = Pattern.compile(pattern); - Matcher m = p.matcher(value); - String val = m.group(1); - - MeasurementDataTrait res = new MeasurementDataTrait(req, val); - report.addData(res); + else { + log.warn("Pattern >>" + pattern + "<< did not match for input >>" + value + "<< and request: >>" + req.getName()); } - else - log.error("Unknown DataType for request " + req); } catch (NagiosException e) {
commit 4556b38891d2422bb71d0c741a4f41796619c50b Author: Heiko W. Rupp hwr@redhat.com Date: Thu May 27 12:14:48 2010 +0200
Use the property part of the request name like for numerical metrics
diff --git a/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java b/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java index 045b167..9e2a663 100644 --- a/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java +++ b/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java @@ -173,7 +173,7 @@ public class NagiosMonitorComponent implements ResourceComponent, MeasurementFac } else if(req.getDataType() == DataType.TRAIT) { - String value = nagiosSystemData.getSingleHostServiceMetric(req.getName(), serviceName, "localhost").getValue(); // TODO use 'real' host + String value = nagiosSystemData.getSingleHostServiceMetric(property, serviceName, "localhost").getValue(); // TODO use 'real' host
Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(value);
commit c04e58fe8f65df94b4c36ced7d877063ec5c7d7f Author: Heiko W. Rupp hwr@redhat.com Date: Thu May 27 12:09:56 2010 +0200
Implement pinging the nagios server for availability checking.
diff --git a/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java b/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java index 3b3be53..045b167 100644 --- a/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java +++ b/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/NagiosMonitorComponent.java @@ -70,8 +70,17 @@ public class NagiosMonitorComponent implements ResourceComponent, MeasurementFac */ public AvailabilityType getAvailability() { - // TODO supply real implementation - return AvailabilityType.UP; + if (context.getParentResourceComponent() instanceof NagiosMonitorComponent) { + return AvailabilityType.UP; // TODO get from parent? + } else { + boolean available = false; + if (nagiosManagementInterface!=null) + available = nagiosManagementInterface.pingNagios(); + + if (available) + return AvailabilityType.UP; + } + return AvailabilityType.DOWN; }
/** diff --git a/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/controller/NagiosManagementInterface.java b/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/controller/NagiosManagementInterface.java index bd5a5dd..8133d23 100644 --- a/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/controller/NagiosManagementInterface.java +++ b/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/controller/NagiosManagementInterface.java @@ -61,6 +61,19 @@ public class NagiosManagementInterface controller = new Controller(); }
+ /** + * Ping the nagios server by sending a host request. + * @return true if >=1 hosts were listed in the answer or false otherwise + */ + public boolean pingNagios() { + LqlHostRequest hostRequest = new LqlHostRequest(); + LqlReply hostReply = livestatusConnectionInterface.sendAndReceive(hostRequest); + if (hostReply.getLqlReply().size()>0) + return true; + + return false; + } + /** * Method does all the necessary steps to get the data about the current nagios hosts *
commit 47af222e4444a437a70924789823a2a878156228 Author: Heiko W. Rupp hwr@redhat.com Date: Thu May 27 12:09:32 2010 +0200
In case of I/O error, bail out with an empty reply
diff --git a/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/network/NetworkConnection.java b/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/network/NetworkConnection.java index 7d21087..8ee8f37 100644 --- a/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/network/NetworkConnection.java +++ b/modules/plugins/nagios/src/main/java/org/rhq/plugins/nagios/network/NetworkConnection.java @@ -118,10 +118,10 @@ public class NetworkConnection { try { - //TODO change the socket handling in livestatus - openConnection(); // TODO move outside the loop to inprove performance -- needs keepalives enabled? + String s = it.next(); + //TODO change the socket handling in livestatus + openConnection(); // TODO move outside the loop to inprove performance -- needs keepalives enabled?
- String s = it.next();
//Write query out to Nagios printWriter.println(s); @@ -138,6 +138,8 @@ public class NetworkConnection catch (IOException e) { log.error("Error in sendAndReceive: " + e.getMessage()); + // return an empty reply and not partial data + return new LqlReply(lqlRequest.getRequestType()); } } //Write whole result list to LqlReply object
commit bd3c688698ed899d7d62919f7d82c0cf67307931 Author: Heiko W. Rupp hwr@redhat.com Date: Thu May 27 11:40:59 2010 +0200
Add ssh-monitoring - ssh version as trait only at the moment.
diff --git a/modules/plugins/nagios/src/main/resources/META-INF/rhq-plugin.xml b/modules/plugins/nagios/src/main/resources/META-INF/rhq-plugin.xml index cad17ba..1e937d8 100644 --- a/modules/plugins/nagios/src/main/resources/META-INF/rhq-plugin.xml +++ b/modules/plugins/nagios/src/main/resources/META-INF/rhq-plugin.xml @@ -45,5 +45,8 @@ <metric property="free_swap|plugin_output|.* \(([\d]+) .*" displayName="Free swap" measurementType="dynamic" units="megabytes" displayType="summary"/> <metric property="free_swap_perc|plugin_output|.* - ([\d]+)%.*" displayName="Free swap percent" measurementType="dynamic" units="none" displayType="summary"/> </service> + <service name="SSH" class="NagiosMonitorComponent" discovery="NagiosMonitorDiscovery" description="SSHD"> + <metric property="ssh_version|plugin_output|.* - (.*)" displayName="SSH Version" dataType="trait" displayType="summary"/> + </service> </server> </plugin>
commit fdf73aec5a496e00c8008d9ddd1ff2577445369c Merge: 5036760... 1149b0f... Author: Heiko W. Rupp hwr@redhat.com Date: Thu May 27 10:31:45 2010 +0200
Merge branch 'master' into nagios
rhq-commits@lists.fedorahosted.org