Class: Ruzbx::Tasks::Jira

Inherits:
Object
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/ruzbx/tasks/zabbix.rb

Overview

TODO

Instance Method Summary collapse

Constructor Details

#initializeJira

Returns a new instance of Jira.



13
14
15
16
17
18
19
# File 'lib/ruzbx/tasks/zabbix.rb', line 13

def initialize
  @options = {
    issuetype: 'Task'
  }
  @parser = OptionParser.new
  define
end

Instance Method Details

#defineObject

rubocop:disable Metrics/AbcSize rubocop:disable Metrics/MethodLength



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ruzbx/tasks/zabbix.rb', line 33

def define
  generate 'whoami' do
    puts Ruzbx::Api::Myself.get.name
  end
  generate 'url' do
    puts Ruzbx::Configuration.url
  end
  generate 'server_info' do
    puts Ruzbx::Api::ServerInfo.get.data.to_json
  end
  generate 'template' do
    parser do
      @parser.banner = "Usage: rake zabbix:template -- '[options]'"
      @parser.on('-n NAME', '--name=NAME') { |name| @options[:name] = name }
    end

    options = @options
    result = Ruzbx::Api::Template.get options[:name]
    result.data['result'].each { |i| puts JSON.pretty_generate(i) }
  end
  generate 'create' do
    parser do
      @parser.banner = "Usage: rake zabbix:create -- '[options]'"
      @parser.on('-n NAME', '--name=NAME') { |name| @options[:name] = name.strip }
      @parser.on('-i IP', '--ip=NAME') { |ip| @options[:ip] = ip }
      @parser.on('-t NAME', '--templates=NAME') { |templates| @options[:templates] = templates.strip.split(',') }
      @parser.on('-g NAME', '--hostgroups=NAME') do |hostgroups|
        @options[:hostgroups] = hostgroups.strip.split(',')
      end
    end

    options = @options
    options[:templates] = Ruzbx::Api::Template.get(options[:templates]).ids.map do |i|
      { templateid: i }
    end
    options[:groups] = Ruzbx::Api::HostGroup.get(options[:hostgroups]).ids.map do |i|
      { groupid: i }
    end
    result = Ruzbx::Api::Host.create options
    result.data['result'].each { |i| puts JSON.pretty_generate(i) }
  end
end

#generate(name, &block) ⇒ Object

rubocop:enable Metrics/AbcSize rubocop:enable Metrics/MethodLength



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ruzbx/tasks/zabbix.rb', line 78

def generate(name, &block)
  fullname = "zabbix:#{name}"
  desc "Run #{fullname}"

  Rake::Task[fullname].clear if Rake::Task.task_defined?(fullname)
  namespace :zabbix do
    task name do
      instance_eval(&block)
    end
  end
end

#options(name) ⇒ Object



27
28
29
# File 'lib/ruzbx/tasks/zabbix.rb', line 27

def options(name)
  @options[name]
end

#parserObject



21
22
23
24
25
# File 'lib/ruzbx/tasks/zabbix.rb', line 21

def parser
  yield
  args = @parser.order!(ARGV) {}
  @parser.parse!(args)
end