Skip to content

Commit 0145f5b

Browse files
committed
Initial import
1 parent ef57039 commit 0145f5b

40 files changed

+1648
-0
lines changed

.classpath

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
</attributes>
13+
</classpathentry>
14+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
15+
<attributes>
16+
<attribute name="optional" value="true"/>
17+
<attribute name="maven.pomderived" value="true"/>
18+
</attributes>
19+
</classpathentry>
20+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
21+
<attributes>
22+
<attribute name="maven.pomderived" value="true"/>
23+
</attributes>
24+
</classpathentry>
25+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
26+
<attributes>
27+
<attribute name="maven.pomderived" value="true"/>
28+
</attributes>
29+
</classpathentry>
30+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
31+
<attributes>
32+
<attribute name="maven.pomderived" value="true"/>
33+
</attributes>
34+
</classpathentry>
35+
<classpathentry kind="output" path="target/classes"/>
36+
</classpath>

.project

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>com.opsvision.monitoring</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
22+
</natures>
23+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
12+
org.eclipse.jdt.core.compiler.source=1.8

.settings/org.eclipse.m2e.core.prefs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1

pom.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>com.opsvision.monitoring</groupId>
4+
<artifactId>com.opsvision.monitoring</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
7+
<dependencies>
8+
<dependency>
9+
<groupId>org.slf4j</groupId>
10+
<artifactId>slf4j-api</artifactId>
11+
<version>1.7.12</version>
12+
</dependency>
13+
<dependency>
14+
<groupId>org.slf4j</groupId>
15+
<artifactId>slf4j-log4j12</artifactId>
16+
<version>1.7.12</version>
17+
</dependency>
18+
<dependency>
19+
<groupId>org.quartz-scheduler</groupId>
20+
<artifactId>quartz</artifactId>
21+
<version>2.2.1</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.snmp4j</groupId>
25+
<artifactId>snmp4j</artifactId>
26+
<version>1.10.1</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.jsoup</groupId>
30+
<artifactId>jsoup</artifactId>
31+
<version>1.8.2</version>
32+
</dependency>
33+
</dependencies>
34+
35+
<build>
36+
<plugins>
37+
<plugin>
38+
<artifactId>maven-compiler-plugin</artifactId>
39+
<configuration>
40+
<source>1.8</source>
41+
<target>1.8</target>
42+
</configuration>
43+
</plugin>
44+
</plugins>
45+
</build>
46+
47+
</project>
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
package com.opsvision.monitoring;
2+
3+
import org.apache.log4j.Logger;
4+
import org.quartz.JobBuilder;
5+
import org.quartz.JobDetail;
6+
import org.quartz.Scheduler;
7+
import org.quartz.SchedulerException;
8+
import org.quartz.SimpleScheduleBuilder;
9+
import org.quartz.Trigger;
10+
import org.quartz.TriggerBuilder;
11+
import org.quartz.impl.StdSchedulerFactory;
12+
13+
import com.opsvision.monitoring.monitors.Monitor;
14+
import com.opsvision.monitoring.monitors.MonitorFactory;
15+
import com.opsvision.monitoring.monitors.MonitorType;
16+
17+
public class MonitoringAgent {
18+
19+
private final static String VERSION = "1.0";
20+
21+
private static final Logger logger = Logger.getLogger(MonitoringAgent.class);
22+
private static Scheduler scheduler = null;
23+
private static boolean stopRequested = false;
24+
private static boolean isRunning = false;
25+
26+
public static void start(String[] args) {
27+
logger.debug("Monitoring Agent: " + VERSION);
28+
29+
try {
30+
// Get a handle for the Scheduler
31+
scheduler = new StdSchedulerFactory().getScheduler();
32+
33+
// Start the Scheduler
34+
scheduler.start();
35+
36+
// Add enabled jobs to the scheduler
37+
for (MonitorType type : MonitorType.values()) {
38+
Monitor m = MonitorFactory.getMonitor(type);
39+
if (m.isEnabled()) {
40+
logger.debug(type + " is enabled");
41+
addJobTrigger(scheduler, m.getClass(), m.getRate());
42+
}
43+
}
44+
45+
// Toggle the running flag
46+
isRunning = true;
47+
48+
} catch(SchedulerException e) {
49+
logger.error(e.getMessage());
50+
}
51+
}
52+
53+
/**
54+
* This method is used to stop our agent activities. If using the
55+
* Apache Commons - Procrun utility to wrap this as a service,
56+
* then this method is called to shutdown the agent.
57+
*
58+
* @param args unused
59+
*/
60+
public static void stop(String[] args) {
61+
logger.debug("Modeo Agent shutting down");
62+
63+
// Toggle the stop flag
64+
stopRequested = true;
65+
66+
if (scheduler != null) {
67+
try {
68+
scheduler.shutdown(true);
69+
70+
} catch (SchedulerException ignore) {
71+
logger.warn(ignore.getMessage());
72+
}
73+
}
74+
}
75+
76+
/**
77+
* If you are using the Advanced Installer to wrap this agent
78+
* so it can run as a Windows service, then this method is
79+
* used to stop the agent activities.
80+
*
81+
*/
82+
public static void stop() {
83+
stop(new String[] { "Args Not Used" });
84+
}
85+
86+
/**
87+
* The main entry point from the command line. We will simply
88+
* call the {@link #start(String[])} method.
89+
*
90+
* @param args unused
91+
*/
92+
public static void main(String[] args) {
93+
logger.info("Starting Modeo Agent, Version " + VERSION);
94+
95+
// We have to go into a loop so that the Windows service
96+
// doesn't exit after starting
97+
while(!stopRequested) {
98+
while(!isRunning) {
99+
start(args);
100+
}
101+
102+
try {
103+
Thread.sleep(1000);
104+
} catch (InterruptedException e) {
105+
// ignore
106+
}
107+
}
108+
}
109+
110+
/**
111+
* This method is used to create both a JobDetail and Trigger. The method
112+
* then adds the JobDetail and Trigger to the Scheduler. Note that we are
113+
* suppressing warnings for using raw types and checking so we need to be
114+
* careful about sending classes that do not implement the Job interface.
115+
*
116+
* @param scheduler An instance of the Quartz Scheduler
117+
* @param jobClass A class implementing the Quartz Job interface
118+
* @param rate An integer value representing the seconds between job runs
119+
*/
120+
@SuppressWarnings({ "rawtypes", "unchecked" })
121+
private static void addJobTrigger(Scheduler scheduler, Class jobClass, Integer rate) {
122+
// Create a job detail
123+
JobDetail job = JobBuilder.newJob(jobClass)
124+
.withIdentity(jobClass.getSimpleName(), "modeo").build();
125+
126+
// Create the trigger
127+
Trigger trigger = TriggerBuilder
128+
.newTrigger()
129+
.withIdentity(jobClass.getSimpleName() + "Trigger", "modeo")
130+
.withSchedule(
131+
SimpleScheduleBuilder.simpleSchedule()
132+
.withIntervalInSeconds(rate).repeatForever())
133+
.build();
134+
135+
try {
136+
scheduler.scheduleJob(job, trigger);
137+
138+
} catch (SchedulerException e) {
139+
logger.error(e.getMessage());
140+
}
141+
}
142+
}

0 commit comments

Comments
 (0)