-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from curationexperts/okc
Add OK Computer checks for core system services
- Loading branch information
Showing
5 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
class ChecksController < ApplicationController | ||
before_action :authenticate_user! | ||
before_action :ensure_admin! | ||
with_themed_layout 'dashboard' | ||
def index | ||
@results = OkComputer::Registry.all.run | ||
end | ||
|
||
private | ||
|
||
def ensure_admin! | ||
authorize! :read, :admin_dashboard | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<h1>System Status</h1> | ||
|
||
|
||
<% @results.each do |r| %> | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
<h3 class="panel-title"><%=r.registrant_name%> </h3> | ||
</div> | ||
<div class="panel-body"> | ||
<span class="text-<%= r.failure_occurred ? 'danger' : 'success' %>"> | ||
<%=r.success?%> | ||
</span> | ||
</div> | ||
</div> | ||
|
||
<%end%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
OkComputer.mount_at = false # do not mount okcomputer endpoint at all | ||
|
||
class HttpCheck < OkComputer::Check | ||
def initialize(url) | ||
@url = url | ||
super() | ||
end | ||
def check | ||
system("curl -s '#{@url}'") ? | ||
mark_message("Check passed") : (mark_failure && mark_message("Check failed")) | ||
end | ||
end | ||
class ServiceCheck < OkComputer::Check | ||
def initialize(service) | ||
@service = service | ||
super() | ||
end | ||
def check | ||
system("systemctl is-active #{@service}") ? | ||
mark_message("Check passed") : (mark_failure && mark_message("Check failed")) | ||
end | ||
end | ||
|
||
|
||
OkComputer::Registry.register "redis", ServiceCheck.new('redis-server') | ||
OkComputer::Registry.register "solr", HttpCheck.new(ENV['SOLR_URL']) | ||
OkComputer::Registry.register "fedora", HttpCheck.new(ENV['FEDORA_URL']) | ||
OkComputer::Registry.register "vips", ServiceCheck.new('tomcat9') | ||
OkComputer::Registry.register "postgres", ServiceCheck.new('postgresql') | ||
OkComputer::Registry.register "antivirus service", ServiceCheck.new('clamav-daemon') | ||
OkComputer::Registry.register "antivirus updates", ServiceCheck.new('clamav-freshclam') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
require 'rails_helper' | ||
|
||
RSpec.describe "/checks", type: :request do | ||
context "not logged in" do | ||
it "redirects" do | ||
get checks_path | ||
expect(response).to redirect_to new_user_session_path | ||
end | ||
end | ||
context "logged in as admin" do | ||
let(:admin) { User.create(email: 'test@example.com', password: '123456', roles: [Role.create(name: 'admin')]) } | ||
before do | ||
sign_in admin | ||
end | ||
|
||
describe "GET /index" do | ||
it "renders a successful response" do | ||
get checks_path | ||
expect(response).to be_successful | ||
expect(assigns(:results)).not_to be_nil | ||
expect(response).to render_template('layouts/hyrax/dashboard') | ||
end | ||
end | ||
end | ||
end |