servermonitor 0.1.0
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.
- checksums.yaml +7 -0
- data/bin/postmailq +5 -0
- data/bin/servermonitor +5 -0
- data/lib/servermonitor.rb +7 -0
- data/lib/servermonitor/mailq.rb +45 -0
- data/lib/servermonitor/megacli_disk_smart_status.rb +69 -0
- data/lib/servermonitor/megacli_vd_status.rb +66 -0
- data/lib/servermonitor/version.rb +3 -0
- metadata +80 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 199ab4f2eae0790eb418305f3e91c055986d0713
         | 
| 4 | 
            +
              data.tar.gz: a1a5c8c350a8d0276fb34e85568ba72207f39139
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 20d04be8475dddd86f429ba00e7f19ff904a292d976417b1760b612620c4a644326a41254af0eb26966211fbf02a1bc4f58c86b9a088384d2e69d01a11a187c2
         | 
| 7 | 
            +
              data.tar.gz: 530490e2f810cf63a9df1db6e750a8dc5f92de8d386ff2bb55bae92ef3ba5b74bd8f5dbaa265f64a1a6dd31b92a6d9852a52c014f6cca3425bed4f23247eac68
         | 
    
        data/bin/postmailq
    ADDED
    
    
    
        data/bin/servermonitor
    ADDED
    
    
| @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            module ServerMonitor
         | 
| 2 | 
            +
             | 
| 3 | 
            +
              class MailqConfiguration
         | 
| 4 | 
            +
                attr_accessor :path, :grep, :critical, :warning, :exit_codes
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                def initialize
         | 
| 7 | 
            +
                  @path       = "/opt/zimbra/common/sbin/postqueue -p"
         | 
| 8 | 
            +
                  @grep       = "/bin/grep"
         | 
| 9 | 
            +
                  @critical   = 50
         | 
| 10 | 
            +
                  @warning    = 40
         | 
| 11 | 
            +
                  @exit_codes = true
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
              class Mailq
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def self.config
         | 
| 18 | 
            +
                  @config ||= MailqConfiguration.new
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def self.configure
         | 
| 22 | 
            +
                  yield(config)
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def self.run
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  queue = `#{self.config.path} | #{self.config.grep} -v 'Mail queue is empty' | #{self.config.grep} -c '^[A-Z0-9]'`
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  # Set the no_msg (number of messages) from queue variable if no_msg does not = 0
         | 
| 30 | 
            +
                  queue == 0 ? no_msg = 0 : no_msg = queue.to_i
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  # Compare and return 0 for success and 1 for error
         | 
| 33 | 
            +
                  if no_msg >= self.config.critical.to_i
         | 
| 34 | 
            +
                    puts "#{no_msg} messages in the postfix mail queue"
         | 
| 35 | 
            +
                    puts exit 1 unless self.config.exit_codes == false
         | 
| 36 | 
            +
                  elsif no_msg >= self.config.warning.to_i
         | 
| 37 | 
            +
                    puts "#{no_msg} messages in the postfix mail queue"
         | 
| 38 | 
            +
                    puts exit 1 unless self.config.exit_codes == false
         | 
| 39 | 
            +
                  else
         | 
| 40 | 
            +
                    puts "#{no_msg} messages in the postfix mail queue"
         | 
| 41 | 
            +
                    puts exit 0 unless self.config.exit_codes == false
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
            end
         | 
| @@ -0,0 +1,69 @@ | |
| 1 | 
            +
            require 'servermonitor/mail'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module ServerMonitor
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              class DiskSMARTConfiguration
         | 
| 6 | 
            +
                attr_accessor :megacli, :grep, :exit_codes, :email_from, :email_to, :smtp_address, :smtp_port, :smtp_username, :smtp_password
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def initialize
         | 
| 9 | 
            +
                  @megacli       = "/usr/sbin/megacli"
         | 
| 10 | 
            +
                  @grep          = "/bin/grep"
         | 
| 11 | 
            +
                  @exit_codes    = false
         | 
| 12 | 
            +
                  @email_from    = nil
         | 
| 13 | 
            +
                  @email_to      = nil
         | 
| 14 | 
            +
                  @smtp_address  = nil
         | 
| 15 | 
            +
                  @smtp_port     = nil
         | 
| 16 | 
            +
                  @smtp_username = nil
         | 
| 17 | 
            +
                  @smtp_password = nil
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              class MegaCliDiskSMARTStatus
         | 
| 22 | 
            +
                def self.config
         | 
| 23 | 
            +
                  @config ||= DiskSMARTConfiguration.new
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                def self.configure
         | 
| 27 | 
            +
                  yield(config)
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                def self.run
         | 
| 31 | 
            +
                  # Get current hostname
         | 
| 32 | 
            +
                  fhostname = `hostname -f`
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  # Get the status for each disk from megacli binary and grep for "Drive has flagged a S.M.A.R.T alert" keyword
         | 
| 35 | 
            +
                  raid_status = `#{self.config.megacli} -LDInfo -Lall -aALL | #{self.config.grep} "Drive has flagged a S.M.A.R.T alert"`
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  # Define eympty array
         | 
| 38 | 
            +
                  in_in = []
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  # Define empty variable for raid state
         | 
| 41 | 
            +
                  smart_status = nil
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  #
         | 
| 44 | 
            +
                  raid_status.each_line { |l| in_in << l.chomp }
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                  # Check S.M.A.R.T status
         | 
| 47 | 
            +
                  in_in.each do |i|
         | 
| 48 | 
            +
                    # Regex matching
         | 
| 49 | 
            +
                    Regexp.new('Drive\s*has\s*flagged\s*a\s*S\.M\.A\.R\.T\s*alert\s*:\s*Yes').match?(i) ? smart_status = "ALERT: YES".upcase : smart_status = "ALERT: NO".upcase
         | 
| 50 | 
            +
                    # Display S.M.A.R.T Status
         | 
| 51 | 
            +
                    if smart_status == "ALERT: NO"
         | 
| 52 | 
            +
                      puts "S.M.A.R.T drive status is " + smart_status.to_s + " on hostname " + fhostname
         | 
| 53 | 
            +
                      puts exit 0 unless self.config.exit_codes == false
         | 
| 54 | 
            +
                    else
         | 
| 55 | 
            +
                      puts "S.M.A.R.T drive status is " + smart_status.to_s + " on hostname " + fhostname
         | 
| 56 | 
            +
                      puts exit 1 unless self.config.exit_codes == false
         | 
| 57 | 
            +
                    end
         | 
| 58 | 
            +
                    # Send email if email_to address is not empty AND if a disk does not return an "Alert: NO"
         | 
| 59 | 
            +
                    if self.config.email_to != nil && smart_status != "ALERT: NO"
         | 
| 60 | 
            +
                      time    = Time.now.strftime("%d.%m.%Y %H:%M")
         | 
| 61 | 
            +
                      subject = "Daily RAID check STARTED on #{fhostname} at #{time}. RAID STATE: #{smart_status}."
         | 
| 62 | 
            +
                      body    = "Daily RAID check: #{smart_status}"
         | 
| 63 | 
            +
                      email   = ServerMonitor::EMail.new(self.config.email_from, self.config.email_to, self.config.smtp_address, self.config.smtp_port, self.config.smtp_username, self.config.smtp_password, subject, body)
         | 
| 64 | 
            +
                      email.deliver
         | 
| 65 | 
            +
                    end
         | 
| 66 | 
            +
                  end
         | 
| 67 | 
            +
                end
         | 
| 68 | 
            +
              end
         | 
| 69 | 
            +
            end
         | 
| @@ -0,0 +1,66 @@ | |
| 1 | 
            +
            require 'servermonitor/mail'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module ServerMonitor
         | 
| 4 | 
            +
             | 
| 5 | 
            +
              class VDConfiguration
         | 
| 6 | 
            +
                attr_accessor :megacli, :grep, :exit_codes, :email_from, :email_to, :smtp_address, :smtp_port, :smtp_username, :smtp_password
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def initialize
         | 
| 9 | 
            +
                  @megacli       = "/usr/sbin/megacli"
         | 
| 10 | 
            +
                  @grep          = "/bin/grep"
         | 
| 11 | 
            +
                  @exit_codes    = false
         | 
| 12 | 
            +
                  @email_from    = nil
         | 
| 13 | 
            +
                  @email_to      = nil
         | 
| 14 | 
            +
                  @smtp_address  = nil
         | 
| 15 | 
            +
                  @smtp_port     = nil
         | 
| 16 | 
            +
                  @smtp_username = nil
         | 
| 17 | 
            +
                  @smtp_password = nil
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              class MegaCliVDStatus
         | 
| 22 | 
            +
                def self.config
         | 
| 23 | 
            +
                  @config ||= VDConfiguration.new
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                def self.configure
         | 
| 27 | 
            +
                  yield(config)
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                def self.run
         | 
| 31 | 
            +
                  # Get current hostname
         | 
| 32 | 
            +
                  fhostname = `hostname -f`
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                  # Get the VD state from megacli binary and grep for "State" keyword
         | 
| 35 | 
            +
                  raid_status = `#{self.config.megacli} -LDInfo -Lall -aALL | #{self.config.grep} "State"`
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  # Define eympty array
         | 
| 38 | 
            +
                  in_in = []
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  # Define empty variable for raid state
         | 
| 41 | 
            +
                  vd_status = nil
         | 
| 42 | 
            +
                  #
         | 
| 43 | 
            +
                  raid_status.each_line { |l| in_in << l.chomp }
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                  # Check virtual drive status
         | 
| 46 | 
            +
                  in_in.each { |i| Regexp.new('State\s*:\s*Optimal').match?(i) ? vd_status = "Optimal".upcase : vd_status = "NOT Optimal".upcase }
         | 
| 47 | 
            +
             | 
| 48 | 
            +
                  # Display VD Status
         | 
| 49 | 
            +
                  if vd_status == "Optimal"
         | 
| 50 | 
            +
                    puts "Virtual drive status is " + vd_status.to_s + " on hostname " + fhostname
         | 
| 51 | 
            +
                    puts exit 0 unless self.config.exit_codes == false
         | 
| 52 | 
            +
                  else
         | 
| 53 | 
            +
                    puts "Virtual drive status is " + vd_status.to_s + " on hostname " + fhostname
         | 
| 54 | 
            +
                    puts exit 1 unless self.config.exit_codes == false
         | 
| 55 | 
            +
                  end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                  if self.config.email_to != nil
         | 
| 58 | 
            +
                    time    = Time.now.strftime("%d.%m.%Y %H:%M")
         | 
| 59 | 
            +
                    subject = "Daily RAID check STARTED on #{fhostname} at #{time}. RAID STATE: #{vd_status}."
         | 
| 60 | 
            +
                    body    = "Daily RAID check: #{vd_status}"
         | 
| 61 | 
            +
                    email   = ServerMonitor::EMail.new(self.config.email_from, self.config.email_to, self.config.smtp_address, self.config.smtp_port, self.config.smtp_username, self.config.smtp_password, subject, body)
         | 
| 62 | 
            +
                    email.deliver
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
              end
         | 
| 66 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,80 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: servermonitor
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Nedim Hadzimahmutovic
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2017-04-17 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: mail
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '2.6'
         | 
| 20 | 
            +
              type: :runtime
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '2.6'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: rspec
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '3.6'
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '3.6'
         | 
| 41 | 
            +
            description: A collection of server monitoring ruby scripts packaged in a gem
         | 
| 42 | 
            +
            email: h.nedim@gmail.com
         | 
| 43 | 
            +
            executables:
         | 
| 44 | 
            +
            - servermonitor
         | 
| 45 | 
            +
            - postmailq
         | 
| 46 | 
            +
            extensions: []
         | 
| 47 | 
            +
            extra_rdoc_files: []
         | 
| 48 | 
            +
            files:
         | 
| 49 | 
            +
            - bin/postmailq
         | 
| 50 | 
            +
            - bin/servermonitor
         | 
| 51 | 
            +
            - lib/servermonitor.rb
         | 
| 52 | 
            +
            - lib/servermonitor/mailq.rb
         | 
| 53 | 
            +
            - lib/servermonitor/megacli_disk_smart_status.rb
         | 
| 54 | 
            +
            - lib/servermonitor/megacli_vd_status.rb
         | 
| 55 | 
            +
            - lib/servermonitor/version.rb
         | 
| 56 | 
            +
            homepage: https://github.com/neidiom/servermonitor
         | 
| 57 | 
            +
            licenses:
         | 
| 58 | 
            +
            - MIT
         | 
| 59 | 
            +
            metadata: {}
         | 
| 60 | 
            +
            post_install_message: 
         | 
| 61 | 
            +
            rdoc_options: []
         | 
| 62 | 
            +
            require_paths:
         | 
| 63 | 
            +
            - lib
         | 
| 64 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 65 | 
            +
              requirements:
         | 
| 66 | 
            +
              - - ">="
         | 
| 67 | 
            +
                - !ruby/object:Gem::Version
         | 
| 68 | 
            +
                  version: '0'
         | 
| 69 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 70 | 
            +
              requirements:
         | 
| 71 | 
            +
              - - ">="
         | 
| 72 | 
            +
                - !ruby/object:Gem::Version
         | 
| 73 | 
            +
                  version: '0'
         | 
| 74 | 
            +
            requirements: []
         | 
| 75 | 
            +
            rubyforge_project: 
         | 
| 76 | 
            +
            rubygems_version: 2.6.14
         | 
| 77 | 
            +
            signing_key: 
         | 
| 78 | 
            +
            specification_version: 4
         | 
| 79 | 
            +
            summary: Server Monitor
         | 
| 80 | 
            +
            test_files: []
         |