class OpsviewRest::Servicecheck

Attributes

opsview[RW]
options[RW]
resource_type[RW]

Public Class Methods

new(opsview, options = {}) click to toggle source
# File lib/opsview_rest/servicecheck.rb, line 9
def initialize(opsview, options = {})
  @options = {
    name: 'Unknown',
    description: 'Unknown',
    keywords: [],
    attribute: nil,
    servicegroup: 'Unknown',
    dependencies: ['Opsview Agent'],
    check_period: '24x7',
    check_interval: '5',
    check_attempts: '3',
    retry_check_interval: '1',
    plugin: 'check_nrpe',
    args: '',
    stalking: nil,
    volatile: false,
    invertresults: false,
    notification_options: 'w,c,r',
    notification_period: nil,
    notification_interval: nil,
    flap_detection_enabled: true,
    checktype: 'Active Plugin',
    save: true,
    replace: false
  }.update options

  @opsview = opsview
  @resource_type = @options[:type]

  @options[:keywords] = @options[:keywords].map { |x| { 'name' => x } }
  @options[:servicegroup] = { 'name' => @options[:servicegroup] }
  @options[:dependencies] = @options[:dependencies].map { |x| { 'name' => x } }
  @options[:check_period] = { 'name' => @options[:check_period] }
  @options[:plugin] = { 'name' => @options[:plugin] }
  @options[:volatile] = (@options[:volatile] ? 1 : 0)
  @options[:invertresults] = (@options[:invertresults] ? 1 : 0)
  @options[:flap_detection_enabled] = (@options[:flap_detection_enabled] ? 1 : 0)
  @options[:checktype] = { 'name' => @options[:checktype] }

  save(@options[:replace]) if @options[:save]
end