esoftware.sigma-component.2.09.source-code.SigmaStatusCheck Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sigma-component Show documentation
Show all versions of sigma-component Show documentation
Sigma knowledge engineering system is an system for developing, viewing and debugging theories in first
order logic. It works with Knowledge Interchange Format (KIF) and is optimized for the Suggested Upper Merged
Ontology (SUMO) www.ontologyportal.org.
import java.io.*;
import java.lang.reflect.Member;
import java.util.*;
import java.util.regex.*;
import java.net.*;
import javax.mail.*;
import javax.mail.internet.*;
/* This code is copyrighted by Articulate Software (c) 2011.
It is released under the GNU Public License .
Users of this code also consent, by use of this code, to credit Articulate Software in any
writings, briefings, publications, presentations, or other representations of any
software which incorporates, builds on, or uses this code.*/
public class SigmaStatusCheck {
private static File emailSentFile = new File("/emailSent.txt"); //Will create a file object called emailSent.txt located in the root directory
/** ***************************************************************
* checkURL checks whether an inputed URL contains the string "SUMO" somewhere in it's HTML body
* @param targetURL is a URL to be checked
* @returns boolean true if the URL contains "SUMO" and false otherwise
*/
private static boolean containsSUMO(String targetURL) {
try {
URL target = new URL(targetURL);
BufferedReader in = new BufferedReader(new InputStreamReader(target.openStream()));
StringBuffer HTMLbuffer = new StringBuffer();
String inputLine;
while ((inputLine = in.readLine()) != null)
HTMLbuffer.append(inputLine);
in.close();
String HTMLtext = HTMLbuffer.toString();
if (HTMLtext.contains("SUMO "))
return true;
else
return false;
}
catch (Exception E) {
E.printStackTrace();
return false;
}
}
/** ***************************************************************
*/
public static void main(String[] args) {
if (!containsSUMO("http://localhost:8080/sigma/KBs.jsp") && !emailSentFile.exists()) {
try {
emailSentFile.createNewFile(); //create empty File
//send email
Properties props = new Properties();
props.put("mail.smtp.host", "owa.mygazoo.com");
props.put("mail.from", "[email protected]");
Session session = Session.getInstance(props, null);
MimeMessage msg = new MimeMessage(session);
msg.setFrom();
msg.setRecipients(Message.RecipientType.TO,
"[email protected]");
msg.setSubject("SIGMA IS DOWN");
msg.setSentDate(new Date());
msg.setText("The Sigma main page at http://sigma.ontologyportal.org:4010/sigma/KBs.jsp is down.");
Transport.send(msg);
System.out.println("Email Sent");
}
catch (MessagingException mex) {
System.out.println("send failed, exception: " + mex);
}
catch (IOException ioex) {
System.out.println("File creation failed, exception: " + ioex);
}
}
else if (containsSUMO("http://localhost:8080/sigma/KBs.jsp") && emailSentFile.exists()) {
try {
//delete file
boolean deleted = emailSentFile.delete();
}
catch (Exception E) {
E.printStackTrace();
}
}
}
}