Skip to content

Commit

Permalink
implemented the smart plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sukhbir-singh committed Jun 26, 2018
0 parents commit 5a73377
Show file tree
Hide file tree
Showing 27 changed files with 240 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
source "https://rubygems.org"

# Declare your gem's dependencies in #{yourplugin}.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec

# assume jquery-rails will be used
gem "jquery-rails"

17 changes: 17 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Your plugin license!

Copyright 2013 Amahi, http://www.amahi.org

This software is licensed under the AGPL v3
https://www.gnu.org/licenses/agpl

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3 changes: 3 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
= Amahi plugin SMART Status

SMART Status for the Amahi platform
38 changes: 38 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
begin
require 'rdoc/task'
rescue LoadError
require 'rdoc/rdoc'
require 'rake/rdoctask'
RDoc::Task = Rake::RDocTask
end

RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Amahi Plugin'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end

# APP_RAKEFILE = File.expand_path("../../../Rakefile", __FILE__)
# load 'rails/tasks/engine.rake'

Bundler::GemHelper.install_tasks

require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end


task :default => :test
Empty file added app/assets/images/.gitkeep
Empty file.
Binary file added app/assets/images/hard_disk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Empty file.
15 changes: 15 additions & 0 deletions app/controllers/smart_statuses_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "smart_statuses/smart_test_util.rb"

class SmartStatusesController < ApplicationController
before_action :admin_required

def index
@page_title = t('smart_status')
unless use_sample_data?
@tests = SmartTestUtil.stats
else
# NOTE: this is to get sample fake data in development
@tests = SmartTestUtil.sample_stats
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ApplicationHelper
end
21 changes: 21 additions & 0 deletions app/views/smart_statuses/index.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- unless @tests.size>0
div.no-content
strong
| No devices found
- else
.settings-table#tests-table
table.settings.table
thead
tr
th.settings-col1= t 'model'
th= t 'device'
th
= t 'health_check'
tbody class="#{@tests.size}"
- @tests.each do | test |
tr class=cycle("odd", "even")
td.settings-col1 = test[:model]
td = test[:device]
td
span[style="color: #{test[:color]}"]
= test[:health_check]
6 changes: 6 additions & 0 deletions config/amahi-plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# human readable name (no localization supported yet)
name: SmartStatus
# class to be mounted
class: SmartStatuses
# root url where this plugin will be mounted
url: /tab/smart_statuses
4 changes: 4 additions & 0 deletions config/initializers/plugin_init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# plugin initialization
t = Tab.new("smart_statuses", "smart_statuses", "/tab/smart_statuses")
# add any subtabs with what you need. params are controller and the label, for example
t.add("index", "details")
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Localization in English

'en':
# put here your string symbols and translations
hello_world: Hello World! (yay for the Amahi plugins!)
smart_status: SMART Status
health_check: Basic Health Check
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SmartStatuses::Engine.routes.draw do
# root of the plugin
root :to => 'smart_statuses#index'
end
Empty file added db/migrate/.gitkeep
Empty file.
4 changes: 4 additions & 0 deletions db/sample-data/smartctl-output-sample1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
smartctl 6.5 2016-05-07 r4318 [x86_64-linux-4.16.16-200.fc27.x86_64] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
8 changes: 8 additions & 0 deletions db/sample-data/smartctl-output-sample2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
smartctl 6.5 2016-05-07 r4318 [x86_64-linux-4.16.16-200.fc27.x86_64] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: FAILED!
Drive failure expected in less than 24 hours. SAVE ALL DATA.
Failed Attributes:
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
3 Spin_Up_Time 0x0007 001 001 011 Pre-fail Always FAILING_NOW 60340
9 changes: 9 additions & 0 deletions lib/smart_statuses.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "smart_statuses/version"
require "smart_statuses/engine"

module SmartStatus
class Lib
# the code for your plugin library here
# or inside lib/smart_statuses/whatever.rb and required here
end
end
8 changes: 8 additions & 0 deletions lib/smart_statuses/engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module SmartStatuses
class Engine < ::Rails::Engine
# NOTE: do not isolate the namespace unless you really really
# want to adjust all your controllers views, etc., making Amahi's
# platform hard to reach from here
# isolate_namespace SmartStatus
end
end
46 changes: 46 additions & 0 deletions lib/smart_statuses/smart_test_util.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class SmartTestUtil
class << self
def stats
@disks = DiskUtils.stats
response = []
@disks.each_with_index do |disk, index|
status = read_smart_status(create_file_and_get_path(disk[:device]))
color = (status=="PASSED")? "green": "red";
response << { model: disk[:model], device: disk[:device],
health_check: status, color: color }
end
return response
end

def create_file_and_get_path(device)
# create the status file and return file path
# need to implement for production
get_sample_file_path(rand(2))
end

def sample_stats
@disks = SampleData.load('disks')
response = []
@disks.each_with_index do |disk, index|
status = read_smart_status(get_sample_file_path(index))
color = (status=="PASSED")? "green": "red";
response << { model: disk[:model], device: disk[:device],
health_check: status, color: color }
end
return response
end

def get_sample_file_path(index)
if index.blank? or index%2 == 0
Rails.root+Dir["plugins/*smart_statuses/db/sample-data/smartctl-output-sample1.txt"][0]
else
Rails.root+Dir["plugins/*smart_statuses/db/sample-data/smartctl-output-sample2.txt"][0]
end
end

def read_smart_status(filepath)
return nil unless File.exists?(filepath)
IO.readlines(filepath)[3][50..-1]
end
end
end
3 changes: 3 additions & 0 deletions lib/smart_statuses/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module SmartStatus
VERSION = "0.0.1"
end
Empty file added lib/tasks/.gitkeep
Empty file.
4 changes: 4 additions & 0 deletions lib/tasks/smart_statuses.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# desc "Explaining what the task does"
# task :smart_statuses do
# # Task goes here
# end
Empty file added script/.gitkeep
Empty file.
6 changes: 6 additions & 0 deletions script/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env ruby

ENGINE_ROOT = File.expand_path('../..', __FILE__)
ENGINE_PATH = File.expand_path('../../lib/smart_statuses/engine', __FILE__)
require 'rails/all'
require 'rails/engine/commands'
25 changes: 25 additions & 0 deletions smart_statuses.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
$:.push File.expand_path("../lib", __FILE__)

# Maintain your gem's version:
require "smart_statuses/version"

# Describe your gem and declare its dependencies:
Gem::Specification.new do |s|
s.name = "smart_statuses"
s.version = SmartStatus::VERSION
s.authors = "Sukhbir Singh"
s.email = ["[email protected]"]
s.homepage = "https://www.amahi.org/apps/smart-status"
s.license = "AGPLv3"
s.summary = %{Monitor the S.M.A.R.T. status of your drives with this Amahi plugin.}
s.description = %{This is an Amahi 11 platform plugin that uses S.M.A.R.T. tools to monitor the status of all drives in an Amahi server.}

s.files = Dir["{app,config,db,lib}/**/*"] + ["LICENSE", "Rakefile", "README.rdoc"]
s.test_files = Dir["test/**/*"]

s.add_dependency "rails", "~> 3.2.12"
s.add_dependency "jquery-rails"

s.add_development_dependency "sqlite3"
end

0 comments on commit 5a73377

Please sign in to comment.