ceph_disk_reporter 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in disk_reporter.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # DiskReporter
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'disk_reporter'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install disk_reporter
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+ require 'disk_reporter'
3
+ require 'colorize'
4
+ class DiskDisplay
5
+
6
+ attr_accessor :disks, :sas2ircu
7
+ def initialize
8
+ self.sas2ircu = Sas2ircu::Parser.new
9
+ self.disks = DiskHandler::Parser.new
10
+ end
11
+
12
+ def do_something
13
+ sas2ircu.cards.each do |card_id, card|
14
+ puts "card: #{card_id}"
15
+ card.backplanes.each do |backplane_id, backplane|
16
+ puts " backplane: #{backplane_id}"
17
+ backplane.expand_slots.slots.each do |slot_id, slot|
18
+ if slot.empty?
19
+ puts " slot: #{slot_id}, EMPTY".yellow
20
+ else
21
+ disk_object = disks.devices.find { |d| d.wnn == slot.guid }
22
+ puts " slot: #{slot_id}, wnn: #{slot.guid}, serial: #{slot.serial_no}"
23
+ if disk_object
24
+ disk_object.partitions.each do |partition|
25
+ puts " Partition: #{partition.name}"
26
+ if partition.fs?
27
+ puts " UUID: #{partition.uuid}, TYPE: #{partition.type}"
28
+ if partition.mounted?
29
+ puts " Mounted at: #{partition.mounted}"
30
+ else
31
+ puts " Not Mounted".red
32
+ end
33
+ if partition.is_ceph?
34
+ puts " Has Ceph"
35
+ if partition.should_have_ceph?
36
+ puts " OK".green
37
+ else
38
+ puts " SHOULD NOT HAVE CEPH"
39
+ end
40
+ else
41
+ puts " No Ceph".yellow
42
+ end
43
+ else
44
+ puts " No Filesystem".green
45
+ end
46
+ end
47
+ else
48
+ puts " Disk is not known to kernel".red
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ DiskDisplay.new.do_something
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'disk_reporter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ceph_disk_reporter"
8
+ spec.version = DiskReporter::VERSION
9
+ spec.authors = ["Stuart Harland"]
10
+ spec.email = ["s.harland@livelinktechnology.net"]
11
+ spec.description = %q{Uses sas2ircu and blkid to determine the status of various disks attached to our JBODS}
12
+ spec.summary = spec.description
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+ spec.bindir = 'bin'
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "colorize"
22
+ spec.add_development_dependency "bundler", "~> 1.3"
23
+ spec.add_development_dependency "rake"
24
+ end
@@ -0,0 +1,157 @@
1
+ #!/bin/env ruby
2
+ require 'json'
3
+ module DiskHandler
4
+ class Disk
5
+ attr_accessor :name, :type, :size, :model, :state, :id, :number, :version, :partitions
6
+
7
+ def device_path
8
+ "/dev/#{name}"
9
+ end
10
+
11
+ def serial_number
12
+ number.strip
13
+ end
14
+
15
+ def wnn
16
+ id.delete(' ')
17
+ end
18
+
19
+ def initialize lsblk_line
20
+ attrs_from_line lsblk_line
21
+ check_smart_capability!
22
+ check_health! if smart_capable?
23
+ parse_smart_info if smart_capable?
24
+ populate_partitions
25
+ end
26
+
27
+ def attrs_from_line lsblk_line
28
+ %w{NAME TYPE SIZE MODEL STATE}.each do |key|
29
+ matches = lsblk_line.match(/#{key}="([^"]*)"/)
30
+ self.send("#{key.downcase}=", matches[1]) if matches
31
+ end
32
+ end
33
+
34
+ def get_smart_info
35
+ `smartctl -i /dev/#{name}`
36
+ end
37
+
38
+ # Is the device SMART capable and enabled
39
+ #
40
+ def smart_capable?
41
+ @smart_available && @smart_enabled
42
+ end
43
+
44
+ # Check the SMART health
45
+ #
46
+ def check_health!
47
+ output = `sudo smartctl -H #{device_path}`
48
+ @smart_healthy = !output.scan(/PASSED/).empty?
49
+ @health_output = output
50
+ end
51
+
52
+ # Parses SMART drive info
53
+ #
54
+ def parse_smart_info
55
+ %w{Id Number Version}.each do |key|
56
+ matches = @capability_output.match(/#{key}:\s+([^\n]*)\n/)
57
+ self.send("#{key.downcase}=", matches[1]) if matches
58
+ end
59
+ end
60
+ # Checks if disk is capable
61
+ #
62
+ def check_smart_capability!
63
+ output = `sudo smartctl -i #{device_path}`
64
+ @smart_available = !output.scan(/SMART support is: Available/).empty?
65
+ @smart_enabled = !output.scan(/SMART support is: Enabled/).empty?
66
+ @capability_output = output
67
+ end
68
+
69
+ def to_h
70
+ { name: name, size: size, model: model, smart_available: @smart_available, smart_enabled: @smart_enabled, wnn: wnn, serial: serial_number, version: version
71
+ }
72
+ end
73
+
74
+ def populate_partitions
75
+ self.partitions = []
76
+ `ls #{device_path}[0-9]* 2>/dev/null`.each_line do |name|
77
+ self.partitions << Partition.new(self, name)
78
+ end
79
+ end
80
+ end
81
+
82
+ class Partition
83
+ attr_accessor :disk, :name, :fs, :uuid, :uuid_sub, :type, :mounted
84
+ BLKID_REGEX = %r[/dev/.*:\sUUID="(.{36})"\s(UUID_SUB="(.{36})"\s)*TYPE="(.*)"\s]
85
+ def initialize(disk, name)
86
+ self.disk = disk
87
+ self.name = name.gsub("\n", "")
88
+ blkid
89
+ end
90
+
91
+ def is_ceph?
92
+ mounted? && mounted.match(%r{/var/lib/ceph/})
93
+ end
94
+
95
+ def should_have_ceph?
96
+ true
97
+ end
98
+
99
+ def mounted?
100
+ !!mounted
101
+ end
102
+
103
+ def fs?
104
+ !!fs
105
+ end
106
+
107
+ def blkid
108
+ response = `blkid #{name}`
109
+ self.fs = $?.exitstatus == 0
110
+ # puts "FS: #{fs}"
111
+ # puts response
112
+ if fs?
113
+
114
+ resp = response.scan(BLKID_REGEX)
115
+ if resp && resp[0]
116
+ self.uuid = resp[0][0]
117
+ self.uuid_sub = resp[0][2]
118
+ self.type = resp[0][3]
119
+ end
120
+ # puts 'check if mounted'
121
+ # puts "grep #{name} /proc/mounts"
122
+ mtab = `grep #{name} /proc/mounts`
123
+ self.mounted = mtab.split(' ')[1] if $?
124
+ end
125
+ end
126
+ end
127
+
128
+ class Parser
129
+ attr_accessor :devices
130
+ def initialize
131
+ self.devices = []
132
+ populate
133
+ end
134
+
135
+
136
+ def to_h
137
+ { disks: devices }
138
+ end
139
+ private
140
+
141
+ def scan_disks
142
+ ds = []
143
+ `lsblk -Pbdo NAME,TYPE,SIZE,MODEL,STATE`.each_line do |line|
144
+ ds << Disk.new(line)
145
+ end
146
+ ds
147
+ end
148
+
149
+ def populate
150
+ scan_disks.each do |d|
151
+ self.devices << d
152
+ end
153
+ end
154
+ end
155
+
156
+ puts JSON.generate Parser.new.to_h if $0 == __FILE__
157
+ end
@@ -0,0 +1,177 @@
1
+ #!/bin/env ruby
2
+ require 'json'
3
+ module Sas2ircu
4
+ class Card
5
+ attr_accessor :id, :backplanes, :drives_by_serial, :drives_by_wnn
6
+
7
+ CARD_REGEX = /\s{3}Enclosure#\s+:\s(\d+)\s{3}Logical ID\s+:\s([0-9a-f]+:[0-9a-f]+)\s{3}Numslots\s+:\s(\d+)\s{3}StartSlot\s+:\s(\d+)/.freeze
8
+
9
+ BACKPLANE_REGEX = /Device is a Hard disk\s{3}Enclosure #\s+:\s(\d+)\s{3}Slot #\s+:\s(\d+)\s{3}SAS Address\s+:\s([a-f0-9\-]+)\s{3}State\s+:\s(.+)\s{3}Size \(in MB\)\/\(in sectors\)\s+:\s([0-9]+)\/([0-9]+)\s{3}Manufacturer\s+:\s(.+)\s{3}Model Number\s+:\s(.+)\s{3}Firmware Revision\s+:\s(.+)\s{3}Serial No\s+:\s(.+)\s{3}GUID\s+:\s([0-9a-f]+)\s+Protocol\s+:\s(.+)\s{3}Drive Type\s+:\s(.+)/.freeze
10
+
11
+ def initialize(id)
12
+ self.id = id
13
+ self.backplanes = {}
14
+ self.drives_by_serial = {}
15
+ self.drives_by_wnn = {}
16
+ populate_backplanes
17
+ end
18
+
19
+ def to_h
20
+ bs = {}
21
+ backplanes.each do |_k,b|
22
+ bs[b.enclosure] = b.to_h
23
+ end
24
+ { backplanes: bs }
25
+ end
26
+
27
+ protected
28
+
29
+ def sas2ircu_lines
30
+ @lines ||= `sas2ircu #{id} display`
31
+ end
32
+
33
+ def populate_backplanes
34
+ sas2ircu_lines.scan(CARD_REGEX).each do |bp|
35
+ self.backplanes[bp[0].to_i] = Backplane.new self, bp[0].to_i, bp[1], bp[2].to_i, bp[3].to_i
36
+ end
37
+ populate_slots
38
+ end
39
+
40
+ def populate_slots
41
+ sas2ircu_lines.scan(BACKPLANE_REGEX).each do |d|
42
+ b = @backplanes[d[0].to_i]
43
+ disk = Disk.new b, d
44
+ b.slots[d[1].to_i] = disk
45
+ self.drives_by_serial[d[9]] = disk
46
+ self.drives_by_wnn[d[10]] = disk
47
+ end
48
+ end
49
+ end
50
+
51
+ class Backplane
52
+ attr_accessor :card, :enclosure, :logical_id, :num_slots, :start_slot, :slots
53
+ def initialize(card = nil, enclosure = nil, logical_id = nil, num_slots = nil, start_slot = nil)
54
+ self.card = card
55
+ self.enclosure = enclosure,
56
+ self.logical_id = logical_id
57
+ self.num_slots = num_slots
58
+ self.start_slot = start_slot
59
+ self.slots = {}
60
+ end
61
+
62
+ def expand_slots
63
+ (start_slot..start_slot+num_slots-1).each do |slot_number|
64
+ self.slots[slot_number] = Disk.new(self) unless slots[slot_number]
65
+ end
66
+ self
67
+ end
68
+
69
+ def to_h
70
+ ss = {}
71
+ slots.each do |_k,s|
72
+ ss[s.slot] = s.to_h
73
+ end
74
+ { enclosure: enclosure, logical_id: logical_id, num_slots: num_slots, start_slot: start_slot, slots: ss }
75
+ end
76
+ end
77
+
78
+ class Disk
79
+ attr_accessor :backplane
80
+ def initialize(backplane, disk_array = nil)
81
+ self.backplane = backplane
82
+ @array = disk_array
83
+ end
84
+
85
+ def empty?
86
+ @array.nil?
87
+ end
88
+
89
+ def slot
90
+ @array[1]
91
+ end
92
+
93
+ def sas_address
94
+ @array[2]
95
+ end
96
+
97
+ def state
98
+ @array[3]
99
+ end
100
+
101
+ def size_mb
102
+ @array[4]
103
+ end
104
+
105
+ def size_sectors
106
+ @array[5]
107
+ end
108
+
109
+ def manufacturer
110
+ @array[6]
111
+ end
112
+
113
+ def model_number
114
+ @array[7]
115
+ end
116
+
117
+ def firmware_revision
118
+ @array[8]
119
+ end
120
+
121
+ def serial_no
122
+ @array[9]
123
+ end
124
+
125
+ def guid
126
+ @array[10]
127
+ end
128
+
129
+ def protocol
130
+ @array[11]
131
+ end
132
+
133
+ def drive_type
134
+ @array[12]
135
+ end
136
+
137
+ def to_h
138
+ {
139
+ slot: slot, state: state, size_mb: size_mb, size_sectors: size_sectors,
140
+ sas_address: sas_address, manufacturer: manufacturer,
141
+ model_number: model_number, firmware_revision: firmware_revision,
142
+ serial_no: serial_no, guid: guid, protocol: protocol, drive_type: drive_type
143
+ }
144
+ end
145
+ end
146
+
147
+ class Parser
148
+
149
+ attr_accessor :cards
150
+
151
+ def initialize
152
+ self.cards = {}
153
+ populate
154
+ end
155
+
156
+ def number_of_cards
157
+ @no_cards ||= `sas2ircu list | grep Index| wc -l`
158
+ @no_cards = @no_cards.delete("\n").to_i
159
+ end
160
+
161
+ def populate
162
+ (0..(number_of_cards - 1)).each do |card_id|
163
+ self.cards[card_id] = Card.new(card_id)
164
+ end
165
+ end
166
+
167
+ def to_h
168
+ cr = {}
169
+ cards.each do |_k,c|
170
+ cr[c.id] = c.to_h
171
+ end
172
+ { cards: cr }
173
+ end
174
+ end
175
+
176
+ puts JSON.generate Parser.new.to_h if $0 == __FILE__
177
+ end
@@ -0,0 +1,3 @@
1
+ module DiskReporter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,2 @@
1
+ require 'disk_reporter/sas2ircu_parser'
2
+ require 'disk_reporter/disk_handler'
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ceph_disk_reporter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Stuart Harland
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-11-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: colorize
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Uses sas2ircu and blkid to determine the status of various disks attached
63
+ to our JBODS
64
+ email:
65
+ - s.harland@livelinktechnology.net
66
+ executables:
67
+ - ceph_disk_display
68
+ extensions: []
69
+ extra_rdoc_files: []
70
+ files:
71
+ - .gitignore
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - bin/ceph_disk_display
77
+ - ceph_disk_reporter.gemspec
78
+ - lib/disk_reporter.rb
79
+ - lib/disk_reporter/disk_handler.rb
80
+ - lib/disk_reporter/sas2ircu_parser.rb
81
+ - lib/disk_reporter/version.rb
82
+ homepage: ''
83
+ licenses:
84
+ - MIT
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.23
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Uses sas2ircu and blkid to determine the status of various disks attached
107
+ to our JBODS
108
+ test_files: []