zabcon 0.0.6 → 0.0.327
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/libs/argument_processor.rb +430 -567
- data/libs/command_help.rb +11 -61
- data/libs/command_tree.rb +480 -280
- data/libs/lexer.rb +846 -0
- data/libs/printer.rb +25 -25
- data/libs/revision.rb +1 -0
- data/libs/utility_items.rb +137 -0
- data/libs/zabbix_server.rb +379 -0
- data/libs/zabcon_commands.rb +558 -0
- data/libs/zabcon_core.rb +177 -316
- data/libs/zabcon_exceptions.rb +4 -4
- data/libs/zabcon_globals.rb +29 -6
- data/zabcon.conf.default +38 -3
- data/zabcon.rb +72 -50
- metadata +23 -48
- data/libs/zbxcliserver.rb +0 -325
data/libs/printer.rb
CHANGED
@@ -19,11 +19,11 @@
|
|
19
19
|
|
20
20
|
##########################################
|
21
21
|
# Subversion information
|
22
|
-
# $Id: printer.rb
|
23
|
-
# $Revision:
|
22
|
+
# $Id: printer.rb 325 2011-09-26 08:57:00Z nelsonab $
|
23
|
+
# $Revision: 325 $
|
24
24
|
##########################################
|
25
25
|
|
26
|
-
require '
|
26
|
+
require 'zbxapi/zdebug'
|
27
27
|
require 'libs/zabcon_globals'
|
28
28
|
|
29
29
|
if RUBY_PLATFORM =~ /.*?mswin.*?/
|
@@ -61,7 +61,7 @@ class OutputPrinter
|
|
61
61
|
@lines=0 # how many lines have been displayed thus far?
|
62
62
|
|
63
63
|
# Check the environment variables to see if screen height has been set
|
64
|
-
EnvVars.instance["
|
64
|
+
EnvVars.instance["lines"]=24 if EnvVars.instance["lines"].nil?
|
65
65
|
end
|
66
66
|
|
67
67
|
def hash_width(item)
|
@@ -170,9 +170,9 @@ class OutputPrinter
|
|
170
170
|
# after n lines have been printed
|
171
171
|
# If @lines is set to -1 a side effect is created where pause is disabled.
|
172
172
|
def pause? (lines=1)
|
173
|
-
if @interactive and EnvVars.instance["
|
173
|
+
if @interactive and EnvVars.instance["lines"]>0 and (@lines>-1) then
|
174
174
|
@lines += lines
|
175
|
-
if @lines>=(EnvVars.instance["
|
175
|
+
if @lines>=(EnvVars.instance["lines"]-1) then
|
176
176
|
pause_msg = "Pause, q to quit, a to stop pausing output"
|
177
177
|
Kernel.print pause_msg
|
178
178
|
if RUBY_PLATFORM =~ /.*?mswin.*?/
|
@@ -207,8 +207,8 @@ class OutputPrinter
|
|
207
207
|
def printline(widths)
|
208
208
|
output="+"
|
209
209
|
widths.each { |width| output+="-"+("-"*width)+"-+" }
|
210
|
-
pause? 1
|
211
210
|
puts output
|
211
|
+
pause? 1
|
212
212
|
end
|
213
213
|
|
214
214
|
#Prints the table header
|
@@ -258,20 +258,20 @@ class OutputPrinter
|
|
258
258
|
end
|
259
259
|
|
260
260
|
def print_array(dataset,cols)
|
261
|
-
debug(6
|
262
|
-
debug(6
|
261
|
+
debug(6,:var=>dataset,:msg=>"dataset",:truncate=>150)
|
262
|
+
debug(6,:var=>cols,:msg=>"cols",:truncate=>50)
|
263
263
|
count=0
|
264
|
-
type=dataset
|
265
|
-
results=dataset
|
264
|
+
type=dataset.type
|
265
|
+
results=dataset.data
|
266
266
|
|
267
|
-
debug(6
|
267
|
+
debug(6,:var=>type,:msg=>"Array type")
|
268
268
|
|
269
|
-
puts "#{dataset
|
269
|
+
puts "#{dataset.type.to_s.capitalize} result set" if EnvVars.instance["echo"]
|
270
270
|
|
271
271
|
if results.length==0
|
272
272
|
puts "Result set empty"
|
273
273
|
elsif results[0].class==Hash then
|
274
|
-
debug(7
|
274
|
+
debug(7,:msg=>"Results type is Hash")
|
275
275
|
header=[]
|
276
276
|
if cols.nil? then
|
277
277
|
case type
|
@@ -299,7 +299,7 @@ class OutputPrinter
|
|
299
299
|
header=cols.split(',')
|
300
300
|
end
|
301
301
|
|
302
|
-
debug(6
|
302
|
+
debug(6,:var=>header,:msg=>"header")
|
303
303
|
|
304
304
|
widths=getcolwidth(results,header)
|
305
305
|
|
@@ -319,7 +319,7 @@ class OutputPrinter
|
|
319
319
|
|
320
320
|
|
321
321
|
else
|
322
|
-
debug(7
|
322
|
+
debug(7,:msg=>"Results type is not Hash, assuming array")
|
323
323
|
widths = getcolwidth(results,["id"]) # always returns an array of widths
|
324
324
|
|
325
325
|
printline(widths) # hacking parameters to overload functions
|
@@ -334,14 +334,14 @@ class OutputPrinter
|
|
334
334
|
|
335
335
|
def print_hash(dataset,cols)
|
336
336
|
puts "Hash object printing not implemented, here is the raw result"
|
337
|
-
p dataset
|
337
|
+
p dataset.result
|
338
338
|
end
|
339
339
|
|
340
340
|
|
341
341
|
def print(dataset,cols)
|
342
342
|
begin
|
343
|
-
debug(6
|
344
|
-
debug(6
|
343
|
+
debug(6,:var=>dataset,:msg=>"Dataset",:truncate=>200)
|
344
|
+
debug(6,:var=>cols,:msg=>"Cols",:truncate=>40)
|
345
345
|
@lines=0
|
346
346
|
if !cols #cols==nil
|
347
347
|
cols_to_show=nil
|
@@ -349,18 +349,18 @@ class OutputPrinter
|
|
349
349
|
cols_to_show=cols.empty? ? nil : cols[:show]
|
350
350
|
end
|
351
351
|
|
352
|
-
puts dataset
|
352
|
+
puts dataset.message if dataset.message
|
353
353
|
|
354
354
|
# p dataset[:result].class
|
355
|
-
if dataset
|
355
|
+
if dataset.data.class==Array then
|
356
356
|
print_array(dataset,cols_to_show)
|
357
|
-
elsif dataset
|
357
|
+
elsif dataset.data.class==Hash then
|
358
358
|
print_hash(dataset,cols_to_show)
|
359
|
-
elsif dataset
|
359
|
+
elsif dataset.data.class!=NilClass then
|
360
360
|
puts "Unknown object received by the print routine"
|
361
|
-
puts "Class type: #{dataset
|
361
|
+
puts "Class type: #{dataset.result.class}"
|
362
362
|
puts "Data:"
|
363
|
-
p dataset
|
363
|
+
p dataset.data
|
364
364
|
end
|
365
365
|
rescue TypeError
|
366
366
|
puts "***********************************************************"
|
data/libs/revision.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
REVISION=327
|
@@ -0,0 +1,137 @@
|
|
1
|
+
#License:: GPL 2.0 http://www.gnu.org/licenses/gpl-2.0.html
|
2
|
+
#Copyright:: Copyright (C) 2009,2010 Andrew Nelson nelsonab(at)red-tux(dot)net
|
3
|
+
#
|
4
|
+
#This program is free software; you can redistribute it and/or
|
5
|
+
#modify it under the terms of the GNU General Public License
|
6
|
+
#as published by the Free Software Foundation; either version 2
|
7
|
+
#of the License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
#This program is distributed in the hope that it will be useful,
|
10
|
+
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
#GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
#You should have received a copy of the GNU General Public License
|
15
|
+
#along with this program; if not, write to the Free Software
|
16
|
+
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
17
|
+
|
18
|
+
##########################################
|
19
|
+
# Subversion information
|
20
|
+
# $Id: utility_items.rb 325 2011-09-26 08:57:00Z nelsonab $
|
21
|
+
# $Revision: 325 $
|
22
|
+
##########################################
|
23
|
+
|
24
|
+
require "zbxapi/zdebug"
|
25
|
+
|
26
|
+
Object.class_eval do
|
27
|
+
def env
|
28
|
+
EnvVars.instance
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
String.class_eval do
|
34
|
+
# String::split2(*options)
|
35
|
+
# Valid options, and ther defaults:
|
36
|
+
# :splitchar = '\s'
|
37
|
+
# pivot string or regex
|
38
|
+
# :include_split = false
|
39
|
+
# :trim_empty = true
|
40
|
+
# trim_empty will remove empty and whitespace characters by default
|
41
|
+
# if include_split is true whitespace characters (but not empty) will
|
42
|
+
# be included if the splitchar is a whitespace character (default)
|
43
|
+
# This is a special split routine which will split str using splitchar as a split point.
|
44
|
+
# If items are within quotes or brackets they will not be split even when splitchar is
|
45
|
+
# found within those quotes or brackets.
|
46
|
+
def split2(*options)
|
47
|
+
defaults={:split_char=>'\s', :include_split=>false, :trim_empty=>true}
|
48
|
+
|
49
|
+
options=
|
50
|
+
if options.empty?
|
51
|
+
defaults
|
52
|
+
else
|
53
|
+
raise "split2 requires parameters to be in hash form" if options[0].class!=Hash
|
54
|
+
unknown_keys=options[0].keys-defaults.keys
|
55
|
+
|
56
|
+
raise "Unknown keys: #{unknown_keys.join(", ")}" if !unknown_keys.empty?
|
57
|
+
defaults.merge(options[0])
|
58
|
+
end
|
59
|
+
|
60
|
+
splitchar=options[:split_char]
|
61
|
+
include_split=options[:include_split]
|
62
|
+
trim_empty=options[:trim_empty]
|
63
|
+
str=self
|
64
|
+
quote_chars=["\"", "'"]
|
65
|
+
left=["(", "{", "["]
|
66
|
+
right=[")", "}", "]"]
|
67
|
+
quote_regex=Regexp.escape(quote_chars.to_s)
|
68
|
+
left_regex=Regexp.escape(left.to_s)
|
69
|
+
right_regex=Regexp.escape(right.to_s)
|
70
|
+
splitchar_regex= Regexp.new(/#{splitchar}/)
|
71
|
+
stack=[]
|
72
|
+
splits=[]
|
73
|
+
result=[]
|
74
|
+
s=StringScanner.new(str)
|
75
|
+
#set up our regex for scanning. We scan for brackets, quotes and escaped characters
|
76
|
+
char_class=Regexp.new("[\\\\#{quote_regex}#{left_regex}#{right_regex}#{splitchar}]")
|
77
|
+
while !s.eos?
|
78
|
+
s.scan_until(char_class)
|
79
|
+
break if !s.matched? # break out if nothing matched
|
80
|
+
ch=str[s.pos-1].chr
|
81
|
+
case ch
|
82
|
+
when "\\" #hande an escaped character by moving the pointer up one
|
83
|
+
s.getch
|
84
|
+
when /[#{quote_regex}]/ #handle a quoted section
|
85
|
+
raise "Unbalanced String: #{str}" if (!stack.index(ch).nil? && stack.index(ch)!=(stack.length-1))
|
86
|
+
if stack.index(ch)==nil
|
87
|
+
stack<<ch
|
88
|
+
else
|
89
|
+
stack.pop
|
90
|
+
end
|
91
|
+
when /[#{left_regex}]/ #open bracket found
|
92
|
+
stack<<left.index(ch)
|
93
|
+
when /[#{right_regex}]/ #close bracket found
|
94
|
+
raise "Unbalanced String: #{str}" if ch!=right[stack.last]
|
95
|
+
stack.pop
|
96
|
+
when /#{splitchar_regex}/ #pivot character found
|
97
|
+
splits<<s.pos-1 if stack.empty?
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
raise "Unbalanced String: #{str}" if !stack.empty?
|
102
|
+
splits<<str.length
|
103
|
+
|
104
|
+
pos=0
|
105
|
+
while !splits.empty?
|
106
|
+
split_pos=splits.first
|
107
|
+
splits.delete(splits.first)
|
108
|
+
result<<str[pos..split_pos-1] if split_pos>0
|
109
|
+
result<<str[split_pos].chr if !str[split_pos].nil? && include_split
|
110
|
+
pos=split_pos+1
|
111
|
+
end
|
112
|
+
|
113
|
+
result=result.delete_if {|item|
|
114
|
+
if include_split
|
115
|
+
#delete the line if nil or empty or the current item is not the splitchar and not full of whitespace
|
116
|
+
item.nil? || item.empty? || (item.scan(/^#{splitchar}$/).empty? && !item.scan(/^\s*$/).empty?)
|
117
|
+
else
|
118
|
+
item.nil? || item.empty? || !item.scan(/^\s*$/).empty?
|
119
|
+
end
|
120
|
+
} if trim_empty
|
121
|
+
|
122
|
+
result
|
123
|
+
end
|
124
|
+
|
125
|
+
def strip_comments
|
126
|
+
splits = self.split2(:split_char=>'#', :include_split=>true)
|
127
|
+
if !(index=splits.index('#')).nil?
|
128
|
+
if index>0
|
129
|
+
splits=splits[0..index-1]
|
130
|
+
else
|
131
|
+
splits=[]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
splits.join.strip
|
135
|
+
end
|
136
|
+
|
137
|
+
end # end String.class_eval
|
@@ -0,0 +1,379 @@
|
|
1
|
+
#GPL 2.0 http://www.gnu.org/licenses/gpl-2.0.html
|
2
|
+
#Zabbix CLI Tool and associated files
|
3
|
+
#Copyright (C) 2009,2010 Andrew Nelson nelsonab(at)red-tux(dot)net
|
4
|
+
#
|
5
|
+
#This program is free software; you can redistribute it and/or
|
6
|
+
#modify it under the terms of the GNU General Public License
|
7
|
+
#as published by the Free Software Foundation; either version 2
|
8
|
+
#of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
#This program is distributed in the hope that it will be useful,
|
11
|
+
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
#GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
#You should have received a copy of the GNU General Public License
|
16
|
+
#along with this program; if not, write to the Free Software
|
17
|
+
#Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
18
|
+
|
19
|
+
##########################################
|
20
|
+
# Subversion information
|
21
|
+
# $Id: zabbix_server.rb 325 2011-09-26 08:57:00Z nelsonab $
|
22
|
+
# $Revision: 325 $
|
23
|
+
##########################################
|
24
|
+
|
25
|
+
require 'zbxapi'
|
26
|
+
require 'zbxapi/zdebug'
|
27
|
+
require 'libs/zabcon_globals'
|
28
|
+
require 'libs/command_tree'
|
29
|
+
|
30
|
+
class ZabbixServer_overload < ZabbixAPI
|
31
|
+
alias zbxapi_initialize initialize
|
32
|
+
alias zbxapi_do_request do_request
|
33
|
+
|
34
|
+
def initialize(url,debug_level=0)
|
35
|
+
@env = env
|
36
|
+
zbxapi_initialize(url,debug_level)
|
37
|
+
end
|
38
|
+
|
39
|
+
#truncate_length is set to the symbol :not_used as do_request is passed a different variable
|
40
|
+
def do_request(json_obj,truncate_length=:not_used)
|
41
|
+
zbxapi_do_request(json_obj,@env["truncate_length"])
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class ZabbixServer
|
46
|
+
|
47
|
+
include Singleton
|
48
|
+
include ZDebug
|
49
|
+
|
50
|
+
class ConnectionProblem < Exception
|
51
|
+
def initialize(msg)
|
52
|
+
@msg=msg
|
53
|
+
end
|
54
|
+
|
55
|
+
def message
|
56
|
+
"There was a problem connecting to the Zabbix server: #{@msg}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
attr_accessor :server_url, :username, :password
|
61
|
+
attr_reader :version, :connected, :connection
|
62
|
+
|
63
|
+
def initialize
|
64
|
+
@server_url=nil
|
65
|
+
@username=nil
|
66
|
+
@password=nil
|
67
|
+
@connected=false
|
68
|
+
@version=nil
|
69
|
+
@connection=nil
|
70
|
+
end
|
71
|
+
|
72
|
+
#login
|
73
|
+
# Perform the actual login to the Zabbix server
|
74
|
+
# If the object variables url, username, and password have not been
|
75
|
+
# set previously, an attempt will be made to use the global environment
|
76
|
+
# variables. If that does not work an exception will be raised.
|
77
|
+
def login
|
78
|
+
@server_url = @server_url.nil? ? env["server"] : @server_url
|
79
|
+
@username = @username.nil? ? env["username"] : @username
|
80
|
+
@password = @password.nil? ? env["password"] : @password
|
81
|
+
|
82
|
+
error_msg=[]
|
83
|
+
error_msg<<"Url not set" if @server_url.nil?
|
84
|
+
error_msg<<"Username not set" if @username.nil?
|
85
|
+
error_msg<<"Password not set" if @password.nil?
|
86
|
+
|
87
|
+
raise ConnectionProblem.new(error_msg.join(", ")) if !error_msg.empty?
|
88
|
+
|
89
|
+
@connection = ZabbixServer_overload.new(@server_url,env["debug"])
|
90
|
+
@connection.login(@username,@password)
|
91
|
+
@connected=true
|
92
|
+
GlobalVars.instance["auth"]=@connection.auth
|
93
|
+
@version=@connection.API_version
|
94
|
+
puts "#{@server_url} connected" if env["echo"]
|
95
|
+
puts "API Version: #{@version}" if env["echo"]
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
def logout
|
100
|
+
begin
|
101
|
+
@connection.logout
|
102
|
+
rescue ZbxAPI_GeneralError => e
|
103
|
+
#if it's -32400, it's probably because the function does not exist.
|
104
|
+
raise e if e.message["code"]!=-32400
|
105
|
+
ensure
|
106
|
+
@connection=nil
|
107
|
+
@connected=false
|
108
|
+
@version=nil
|
109
|
+
GlobalVars.instance.delete("auth")
|
110
|
+
puts "Logout complete from #{@server_url}" if env["echo"]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def loggedin?
|
115
|
+
@connected
|
116
|
+
end
|
117
|
+
|
118
|
+
#TODO come back and finish the class to have automated
|
119
|
+
#timeout of the connection, and improve the usability of
|
120
|
+
#this function which should tell you if you have a valid
|
121
|
+
#connection or not, which includes timeout and login.
|
122
|
+
def connected?
|
123
|
+
@connected
|
124
|
+
end
|
125
|
+
|
126
|
+
def version
|
127
|
+
@connection.API_version
|
128
|
+
end
|
129
|
+
|
130
|
+
def reconnect
|
131
|
+
@connection.login(@user,@password)
|
132
|
+
end
|
133
|
+
|
134
|
+
# def getuser(parameters)
|
135
|
+
# debug(6,parameters)
|
136
|
+
#
|
137
|
+
# result=@connection.user.get(parameters)
|
138
|
+
# {:class=>:user, :result=>result}
|
139
|
+
# end
|
140
|
+
#
|
141
|
+
# def gethost(parameters)
|
142
|
+
# debug(6,parameters)
|
143
|
+
#
|
144
|
+
# result=@connection.host.get(parameters)
|
145
|
+
# {:class=>:host, :result=>result}
|
146
|
+
# end
|
147
|
+
|
148
|
+
# def addhost(parameters)
|
149
|
+
# debug(6,parameters)
|
150
|
+
# result=@connection.host.create(parameters)
|
151
|
+
# {:class=>:host, :message=>"The following host was created: #{result['hostids']}", :result=>result}
|
152
|
+
# end
|
153
|
+
|
154
|
+
# def deletehost(parameters)
|
155
|
+
# debug(6,parameters)
|
156
|
+
# result=@connection.host.delete(parameters)
|
157
|
+
# {:class=>:host, :message=>"The following host(s) was/were deleted: #{result['hostids']}", :result=>result}
|
158
|
+
# end
|
159
|
+
|
160
|
+
# def getitem(parameters)
|
161
|
+
# debug(6,parameters)
|
162
|
+
#
|
163
|
+
# result=@connection.item.get(parameters)
|
164
|
+
# {:class=>:item, :result=>result}
|
165
|
+
# end
|
166
|
+
|
167
|
+
# def additem(parameters)
|
168
|
+
# debug(6,parameters)
|
169
|
+
# {:class=>:item, :result=>@connection.item.create(parameters)}
|
170
|
+
# end
|
171
|
+
|
172
|
+
# def deleteitem(parameters)
|
173
|
+
# debug(6,parameters)
|
174
|
+
# {:class=>:item, :result=>@connection.item.delete(parameters)}
|
175
|
+
# end
|
176
|
+
|
177
|
+
# def adduser(parameters)
|
178
|
+
# debug(6,parameters)
|
179
|
+
# begin
|
180
|
+
# uid=@connection.user.create(parameters)
|
181
|
+
# puts "Created userid: #{uid["userids"]}"
|
182
|
+
# rescue ZbxAPI_ParameterError => e
|
183
|
+
# puts "Add user failed, error: #{e.message}"
|
184
|
+
# end
|
185
|
+
# end
|
186
|
+
|
187
|
+
# def deleteuser(parameter)
|
188
|
+
# debug(6,parameter)
|
189
|
+
# id=0 #id to delete
|
190
|
+
## if parameters.nil? then
|
191
|
+
## puts "User id required"
|
192
|
+
## return
|
193
|
+
## end
|
194
|
+
#
|
195
|
+
# if !parameter["name"].nil?
|
196
|
+
# users=@connection.user.get({"pattern"=>parameter["name"], "extendoutput"=>true})
|
197
|
+
# users.each { |user| id=user["userid"] if user["alias"]==parameter }
|
198
|
+
# else
|
199
|
+
# id=parameter["id"]
|
200
|
+
# end
|
201
|
+
# result=@connection.user.delete(id)
|
202
|
+
# if !result.empty?
|
203
|
+
# puts "Deleted user id #{result["userids"]}"
|
204
|
+
# else
|
205
|
+
# puts "Error deleting #{parameter.to_a[0][1]}"
|
206
|
+
# end
|
207
|
+
# end
|
208
|
+
|
209
|
+
# def updateuser(parameters)
|
210
|
+
# debug(6,parameters)
|
211
|
+
# valid_parameters=['userid','name', 'surname', 'alias', 'passwd', 'url', 'autologin',
|
212
|
+
# 'autologout', 'lang', 'theme', 'refresh', 'rows_per_page', 'type',]
|
213
|
+
# if parameters.nil? or parameters["userid"].nil? then
|
214
|
+
# puts "Edit User requires arguments, valid fields are:"
|
215
|
+
# puts "name, surname, alias, passwd, url, autologin, autologout, lang, theme, refresh"
|
216
|
+
# puts "rows_per_page, type"
|
217
|
+
# puts "userid is a required field"
|
218
|
+
# puts "example: edit user userid=<id> name=someone alias=username passwd=pass autologout=0"
|
219
|
+
# return false
|
220
|
+
# else
|
221
|
+
# p_keys = parameters.keys
|
222
|
+
#
|
223
|
+
# valid_parameters.each {|key| p_keys.delete(key)}
|
224
|
+
# if !p_keys.empty? then
|
225
|
+
# puts "Invalid items"
|
226
|
+
# p p_keys
|
227
|
+
# return false
|
228
|
+
# elsif parameters["userid"].nil?
|
229
|
+
# puts "Missing required userid statement."
|
230
|
+
# end
|
231
|
+
# p @connection.user.update([parameters]) #TODO: remove print statement or comment if needed
|
232
|
+
# end
|
233
|
+
# end
|
234
|
+
|
235
|
+
def addusermedia(parameters)
|
236
|
+
debug(6,:var=>parameters)
|
237
|
+
valid_parameters=["userid", "mediatypeid", "sendto", "severity", "active", "period"]
|
238
|
+
|
239
|
+
if parameters.nil? then
|
240
|
+
puts "add usermedia requires arguments, valid fields are:"
|
241
|
+
puts "userid, mediatypeid, sendto, severity, active, period"
|
242
|
+
puts "example: add usermedia userid=<id> mediatypeid=1 sendto=myemail@address.com severity=63 active=1 period=\"\""
|
243
|
+
else
|
244
|
+
|
245
|
+
p_keys = parameters.keys
|
246
|
+
|
247
|
+
valid_parameters.each {|key| p_keys.delete(key)}
|
248
|
+
if !p_keys.empty? then
|
249
|
+
puts "Invalid items"
|
250
|
+
p p_keys
|
251
|
+
return false
|
252
|
+
elsif parameters["userid"].nil?
|
253
|
+
puts "Missing required userid statement."
|
254
|
+
end
|
255
|
+
begin
|
256
|
+
@connection.user.addmedia(parameters)
|
257
|
+
rescue ZbxAPI_ParameterError => e
|
258
|
+
puts e.message
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
end
|
263
|
+
|
264
|
+
# def addhostgroup(parameters)
|
265
|
+
# debug(6,parameters)
|
266
|
+
# result = @connection.hostgroup.create(parameters)
|
267
|
+
# {:class=>:hostgroup, :result=>result}
|
268
|
+
# end
|
269
|
+
|
270
|
+
# def gethostgroup(parameters)
|
271
|
+
# debug(6,parameters)
|
272
|
+
#
|
273
|
+
# result=@connection.hostgroup.get(parameters)
|
274
|
+
# {:class=>:hostgroup, :result=>result}
|
275
|
+
# end
|
276
|
+
|
277
|
+
def gethostgroupid(parameters)
|
278
|
+
debug(6,:var=>parameters)
|
279
|
+
result = @connection.hostgroup.getObjects(parameters)
|
280
|
+
{:class=>:hostgroupid, :result=>result}
|
281
|
+
end
|
282
|
+
|
283
|
+
# def getapp(parameters)
|
284
|
+
# debug(6,parameters)
|
285
|
+
#
|
286
|
+
# result=@connection.application.get(parameters)
|
287
|
+
# {:class=>:application, :result=>result}
|
288
|
+
# end
|
289
|
+
#
|
290
|
+
# def addapp(parameters)
|
291
|
+
# debug(6,parameters)
|
292
|
+
# result=@connection.application.create(parameters)
|
293
|
+
# {:class=>:application, :result=>result}
|
294
|
+
# end
|
295
|
+
|
296
|
+
def getappid(parameters)
|
297
|
+
debug(6,:var=>parameters)
|
298
|
+
result=@connection.application.getid(parameters)
|
299
|
+
{:class=>:application, :result=>result}
|
300
|
+
end
|
301
|
+
|
302
|
+
def gettrigger(parameters)
|
303
|
+
debug(6,:var=>parameters)
|
304
|
+
result=@connection.trigger.get(parameters)
|
305
|
+
{:class=>:trigger, :result=>result}
|
306
|
+
end
|
307
|
+
|
308
|
+
# # addtrigger( { trigger1, trigger2, triggern } )
|
309
|
+
# # Only expression and description are mandatory.
|
310
|
+
# # { { expression, description, type, priority, status, comments, url }, { ...} }
|
311
|
+
# def addtrigger(parameters)
|
312
|
+
# debug(6,parameters)
|
313
|
+
# result=@connection.trigger.create(parameters)
|
314
|
+
# {:class=>:trigger, :result=>result}
|
315
|
+
# end
|
316
|
+
|
317
|
+
def addlink(parameters)
|
318
|
+
debug(6,:var=>parameters)
|
319
|
+
result=@connection.sysmap.addlink(parameters)
|
320
|
+
{:class=>:map, :result=>result}
|
321
|
+
end
|
322
|
+
|
323
|
+
def addsysmap(parameters)
|
324
|
+
debug(6,:var=>parameters)
|
325
|
+
result=@connection.sysmap.create(parameters)
|
326
|
+
{:class=>:map, :result=>result}
|
327
|
+
end
|
328
|
+
|
329
|
+
def addelementtosysmap(parameters)
|
330
|
+
debug(6,:var=>parameters)
|
331
|
+
result=@connection.sysmap.addelement(parameters)
|
332
|
+
{:class=>:map, :result=>result}
|
333
|
+
end
|
334
|
+
|
335
|
+
def getseid(parameters)
|
336
|
+
debug(6,:var=>parameters)
|
337
|
+
result=@connection.sysmap.getseid(parameters)
|
338
|
+
{:class=>:map, :result=>result}
|
339
|
+
end
|
340
|
+
|
341
|
+
def addlinktrigger(parameters)
|
342
|
+
debug(6,:var=>parameters)
|
343
|
+
result=@connection.sysmap.addlinktrigger(parameters)
|
344
|
+
{:class=>:map, :result=>result}
|
345
|
+
end
|
346
|
+
|
347
|
+
# def raw_api(parameters)
|
348
|
+
# debug(6,parameters)
|
349
|
+
# result=@connection.raw_api(parameters[:method],parameters[:params])
|
350
|
+
# {:class=>:raw, :result=>result}
|
351
|
+
# end
|
352
|
+
|
353
|
+
# def raw_json(parameters)
|
354
|
+
# debug(6,parameters)
|
355
|
+
# begin
|
356
|
+
# result=@connection.do_request(parameters)
|
357
|
+
# {:class=>:raw, :result=>result["result"]}
|
358
|
+
# rescue ZbxAPI_GeneralError => e
|
359
|
+
# puts "An error was received from the Zabbix server"
|
360
|
+
# if e.message.class==Hash
|
361
|
+
# puts "Error code: #{e.message["code"]}"
|
362
|
+
# puts "Error message: #{e.message["message"]}"
|
363
|
+
# puts "Error data: #{e.message["data"]}"
|
364
|
+
# end
|
365
|
+
# puts "Original text:"
|
366
|
+
# puts parameters
|
367
|
+
# puts
|
368
|
+
# return {:class=>:raw, :result=>nil}
|
369
|
+
# end
|
370
|
+
# end
|
371
|
+
|
372
|
+
end
|
373
|
+
|
374
|
+
##############################################
|
375
|
+
# Unit test
|
376
|
+
##############################################
|
377
|
+
|
378
|
+
if __FILE__ == $0
|
379
|
+
end
|