Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding healthchecks #830

Open
wants to merge 5 commits into
base: dtq-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.health;

import org.dspace.health.additionalUtilities.Info;

public class AdditionalInfoCheck extends Check {

@Override
protected String run(ReportInfo ri) {
String output = "";

output += String.format(
"Server uptime: %s\n", Info.get_proc_uptime());
output += String.format(
"JVM uptime: %s\n", Info.get_jvm_uptime());
output += String.format(
"Testing build time: %s\n", Info.get_build_time());

output += "\n\n";

output += "Example url 1: https://dev-5.pc:8443/repository/home\n";
output += "Example url 2: https://dev-5.pc:85/repository/home\n";
return output;
}
}
35 changes: 35 additions & 0 deletions dspace-api/src/main/java/org/dspace/health/OAIPMHCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.health;

import org.dspace.health.additionalUtilities.IOUtils;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;

import java.io.File;

public class OAIPMHCheck extends Check {
protected static final ConfigurationService configurationService
= DSpaceServicesFactory.getInstance().getConfigurationService();

@Override
protected String run(ReportInfo ri) {
String output = "";
String dspace_dir = configurationService.getProperty("dspace.dir");
String dspace_url = configurationService.getProperty("dspace.server.url");
String oaiurl = dspace_url + "/oai/request";
output += String.format("Trying [%s]\n", oaiurl);

File scriptDir = new File(
"C:\\WorkSpace\\DSpace\\dspace-api\\src\\main\\java\\org\\dspace\\health\\additionalUtilities\\");

output += IOUtils.runScript(scriptDir, new String[]{
"python", "validate.py", oaiurl});
return output;
}
}
127 changes: 127 additions & 0 deletions dspace-api/src/main/java/org/dspace/health/ShibbolethCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.health;

import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class ShibbolethCheck extends Check {

protected static final ConfigurationService configurationService
= DSpaceServicesFactory.getInstance().getConfigurationService();

@Override
protected String run(ReportInfo ri) {
// StringBuilder ret = new StringBuilder();
// final String input_dir = configurationService.getProperty("lr",
// "lr.shibboleth.log.path");
// final String default_log = configurationService.getProperty("lr",
// "lr.shibboleth.log.defaultName");
//
// String input_file = new File(input_dir, default_log).toString();
//
// ret.append(String.format("Parsing %s:\n", input_file));
// BufferedReader safe_reader = null;
// try {
// safe_reader = IOUtils.safe_reader(input_file);
// // output warnings
// ShibUserLogins user_logins = new ShibUserLogins(safe_reader);
// if (0 < user_logins.warnings().size()) {
// for (String warning : user_logins.warnings()) {
// ret.append(warning + "\n");
// }
// } else {
// ret.append("No shibboleth warnings have been found.\n");
// }
// } catch (Exception e) {
// error(e, String.format("Problematic file [%s]", default_log));
// return ret.toString();
// }
//
// // > WARN from shibd_warn in the last week
// ret.append("\nParsing shibd_warn.*:\n");
// File dir = new File(input_dir);
// String[] files = dir.list(new java.io.FilenameFilter() {
// @Override
// public boolean accept(File dir, String name) {
// return name.contains("shibd_warn");
// }
// });
// Long nowMillis = System.currentTimeMillis();
// String weekAgo = new SimpleDateFormat("yyyy-MM-dd").format(new Date(
// nowMillis - 604800000));
// String[] cmd = new String[] { "awk", "-v", "from=" + weekAgo,
// "BEGIN{FS=\" \"} {if($1>=from) print $0}" };
// String[] cmdWithFiles = new String[cmd.length + files.length];
// System.arraycopy(cmd, 0, cmdWithFiles, 0, cmd.length);
// System.arraycopy(files, 0, cmdWithFiles, cmd.length, files.length);
// try {
// Process child = Runtime.getRuntime().exec(cmdWithFiles, null, dir);
// BufferedReader[] outputs = new BufferedReader[] {
// new BufferedReader(new InputStreamReader(
// child.getInputStream())),
// new BufferedReader(new InputStreamReader(
// child.getErrorStream())) };
// for (BufferedReader out : outputs) {
// String s = null;
// while ((s = out.readLine()) != null) {
// ret.append(s);
// ret.append("\n");
// }
// }
// } catch (java.io.IOException e) {
// error(e);
// }
//
//
// try {
// String feedsConfig = configurationService.getProperty("discojuice", "feeds");
// ret.append(String.format( "Using these static discojuice feeds [%s] as source.\n",
// feedsConfig ));
// // Try to download our feeds file, so the proper action is triggered
// StringWriter writer = new StringWriter();
// org.apache.commons.io.IOUtils.copy(
// new URL(configurationService.getProperty("dspace.url")
// + "/discojuice/feeds").openStream(), writer);
// String json = writer.toString();
// // end download
// Set<String> entities = new HashSet<String>();
// JSONParser parser = new JSONParser();
// JSONArray entityArray = (JSONArray) parser.parse(json);
// Iterator<JSONObject> i = entityArray.iterator();
// int counter = 0;
// while (i.hasNext()) {
// counter++;
// JSONObject entity = i.next();
// String entityID = (String) entity.get("entityID");
// entities.add(entityID);
// }
// int idCount = entities.size();
// ret.append(String.format(
// "Our feeds file contains %d entities out of which %d are unique.\n"
// + "This number should be around 1200?? (20.11.2014).",
// counter, idCount)
// );
// } catch (Exception e) {
// error(e);
// }
//
// return ret.toString();
return "Space for shibboleth output.";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.health.additionalUtilities;

import org.apache.logging.log4j.Logger;

import java.io.BufferedReader;
import java.io.EOFException;
import java.io.File;
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Date;

public class IOUtils {
private static Logger log = org.apache.logging.log4j.LogManager.getLogger(IOUtils.class);

public static String runScript(File where, String[] cmd) {
String message = null;
try {
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.directory( where );
Process p = pb.start();
BufferedReader std_out = new BufferedReader(new InputStreamReader(p.getInputStream()) );
BufferedReader std_err = new BufferedReader(new InputStreamReader(p.getErrorStream()) );

String s = null;
message = "Returned stdout:\n";
while ((s = std_out.readLine()) != null) {
message += s + "\n ";
}
message += "Returned stderr:\n";
while ((s = std_err.readLine()) != null) {
message += s + "\n ";
}

//Wait to get exit value
int exitValue = p.waitFor();
message += "Exit code: [" + String.valueOf( exitValue ) + "]\n";

} catch (Exception e) {
message += "\nException:" + e.toString();
log.error( e );
}
return message;
}

/**
*
* @param input_file
* @return
* @throws InstantiationException
*/
static public BufferedReader safe_reader( String input_file )
throws EOFException, InstantiationException
{

File file = new File(input_file);
String file_id = file.getPath();

if( !file.exists() ) {
throw new InstantiationException( file_id + " does not exist!" );
}
if( file.exists() && 0 == file.length() ) {
throw new EOFException( file_id + " is empty!" );
}

BufferedReader reader = null;
try {
reader = new BufferedReader(
new InputStreamReader(new FileInputStream(file), Charset.forName("UTF8")) );
} catch( IOException e ) {
throw new InstantiationException( file_id + " exception while reading: " + e.toString() );
}

return reader;
}

static public String today_string() {
return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.health.additionalUtilities;

import java.io.FileInputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.Scanner;

import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
//import src.main.java.org.dspace.xoai.services.impl.config.DSpaceConfigurationService;

public class Info {

protected static final ConfigurationService configurationService
= DSpaceServicesFactory.getInstance().getConfigurationService();

final static public String get_proc_uptime() {
String uptime = "unknown";
try {
//works only on linux
uptime = new Scanner(new FileInputStream("/proc/uptime")).next();
System.out.println("\nUPTIME " + uptime);
float fuptime = Float.parseFloat( uptime );
int seconds = (int) (fuptime % 60);
int minutes = (int) ((fuptime / 60) % 60);
int hours = (int) ((fuptime / (60 * 60)) % 24);
int days = (int) ((fuptime / (60 * 60 * 24)) );
return Integer.toString( days ) + "d " +
Integer.toString( hours ) + "h:" +
Integer.toString( minutes ) + "m." +
Integer.toString( seconds );
} catch (Exception e) {
return uptime;
}
}

final static public String get_jvm_uptime() {
RuntimeMXBean mxBean = ManagementFactory.getRuntimeMXBean();
long milliseconds = mxBean.getUptime();
int seconds = (int) (milliseconds / 1000) % 60 ;
int minutes = (int) ((milliseconds / (1000 * 60)) % 60);
int hours = (int) ((milliseconds / (1000 * 60 * 60)) % 24);
int days = (int) ((milliseconds / (1000 * 60 * 60 * 24)));

return Integer.toString( days ) + "d " +
Integer.toString( hours ) + "h:" +
Integer.toString( minutes ) + "m." +
Integer.toString( seconds );
}

final static public String get_build_time() {
//springacka do nespring triedy, chceme autowired, component
String buildTime = configurationService.getProperty("testing-config");
if (buildTime != null && !buildTime.equals("")) {
return buildTime;
}
return "unknown";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
"""
oval
~~~~

BASE OAI-PMH Validity Checker

:copyright: Copyright 2011 Mathias Loesch.
"""

import os
import oval

this_dir, this_filename = os.path.split(__file__)

DATA_PATH = os.path.join(this_dir, "data")
__version__ = '0.2.0'
OAI_PMH_VERSION = '2.0'


def compress(_list):
_list.remove(_list[0])
return [item for item in _list if item != '']


iso_639_file = open(
os.path.join(DATA_PATH, 'iso-639-3.tab'), 'r', encoding='utf-8'
)
ISO_639_3_CODES = compress([line.split('\t')[0] for line in iso_639_file])
iso_639_file.seek(0)
ISO_639_2B_CODES = compress([line.split('\t')[1] for line in iso_639_file])
iso_639_file.seek(0)
ISO_639_2T_CODES = compress([line.split('\t')[2] for line in iso_639_file])
iso_639_file.seek(0)
ISO_639_1_CODES = compress([line.split('\t')[3] for line in iso_639_file])
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Loading