[Xymon] Creating Java Monitor for Xymon
Foster Patch
Foster.Patch at accuweather.com
Wed Feb 17 21:00:29 CET 2016
Hello, I have created a Java Program that will pull a date from a stored procedure in a SQL Server, which then is compared to the current date, and will alarm red if it is past the threshold. Thus far, I have developed the code independent of Xymon, but now plan on implementing it since it is functioning properly. Below is my java code. Instead of printing out "Uh oh" if the date is older than 2 hours, I would like to make it alarm on the servers page. I don't know where to begin from here, and any suggestions or pointers in the right direction would be great. Additionally, any examples of using Java as a monitor in Xymon would be very beneficial. I plan on storing this in \ext\trunk\monitor.d\120.
package connect;
import java.sql.DriverManager;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class Sqlselection {
public static void main(String[] args) throws SQLException, ClassNotFoundException {
CallableStatement callableStatement = null;
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection("jdbc:sqlserver://sqldev-v02.accu.accuwx.com;database=analysis_summary;integratedSecurity=true;");
String getCall = "{call proc_Return_Latest_AirQuality_DateTime}";
callableStatement = conn.prepareCall(getCall);
ResultSet rs = callableStatement.executeQuery();
while (rs.next()) {
String delims = "[.]+";
String seconddelim = "[- :]+";
String columnValue = rs.getString(1);
String[] tokens = columnValue.split(delims);
String checkTime[] = tokens[0].split(seconddelim);
int year = Integer.parseInt(checkTime[0]);
int month = Integer.parseInt(checkTime[1]);
int day = Integer.parseInt(checkTime[2]);
int hour = Integer.parseInt(checkTime[3]);
int minute = Integer.parseInt(checkTime[4]);
int second = Integer.parseInt(checkTime[5]);
Calendar cal = Calendar.getInstance();
Date todayDate = new Date();
todayDate = cal.getTime();
Date checkDate = new Date();
checkDate.setYear(year-1900);
checkDate.setMonth(month);
checkDate.setDate(day);
checkDate.setHours(hour);
checkDate.setMinutes(minute);
checkDate.setSeconds(second);
todayDate.setHours(todayDate.getHours()-2);
if(checkDate.before(todayDate)){
System.out.println("UH OH");
}
else if(checkDate.after(todayDate)){
System.out.println("yep");
}
}
}
}
Foster Patch
Web Server Technician
[cid:image001.png at 01D101D9.AE813790] AccuWeather
385 Science Park Road, State College, PA 16803
P: 814.235.8650
E: Foster.Patch at accuweather.com<mailto:Foster.Patch at accuweather.com>
E: networkoperations at accuweather.com<mailto:networkoperations at accuweather.com>
http://www.AccuWeather.com<http://www.accuweather.com/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xymon.com/pipermail/xymon/attachments/20160217/7c26ac6b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Picture (Device Independent Bitmap) 1.jpg
Type: image/jpeg
Size: 753 bytes
Desc: Picture (Device Independent Bitmap) 1.jpg
URL: <http://lists.xymon.com/pipermail/xymon/attachments/20160217/7c26ac6b/attachment.jpg>
More information about the Xymon
mailing list