Class: Inspec::Resources::Monit

Inherits:
MonitoringTool show all
Defined in:
lib/inspec/resources/service.rb

Instance Attribute Summary

Attributes inherited from MonitoringTool

#inspec, #service_name

Instance Method Summary collapse

Methods inherited from MonitoringTool

#find_utility_or_error, #initialize

Constructor Details

This class inherits a constructor from Inspec::Resources::MonitoringTool

Instance Method Details

#is_service_monitored?Boolean

Returns:

  • (Boolean)

Raises:



945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
# File 'lib/inspec/resources/service.rb', line 945

def is_service_monitored?
  utility = find_utility_or_error("monit")
  utility_cmd = inspec.command("#{utility} summary")

  raise Inspec::Exceptions::ResourceFailed, "Executing #{utility} summary failed: #{utility_cmd.stderr}" if utility_cmd.exit_status.to_i != 0

  monitoring_info = utility_cmd.stdout.split("\n")
  monitoring_info.map! { |info| info.strip.squeeze(" ") }
  is_monitored = false
  monitoring_info.each do |info|
    if info =~ /^#{service_name} OK.*/
      is_monitored = true
      break
    end
  end
  is_monitored
end