zabcon 0.0.356 → 0.0.357
Sign up to get free protection for your applications and to get access to all the features.
- data/libs/revision.rb +1 -1
- data/libs/zabbix_server.rb +23 -0
- data/libs/zabcon_commands.rb +9 -3
- data/libs/zabcon_core.rb +19 -1
- data/revision_information +5 -1
- data/zabcon.conf.default +6 -0
- data/zabcon.rb +7 -0
- metadata +3 -3
data/libs/revision.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
REVISION=
|
1
|
+
REVISION=357
|
data/libs/zabbix_server.rb
CHANGED
@@ -31,6 +31,8 @@ class ZabbixServer_overload < ZabbixAPI
|
|
31
31
|
alias zbxapi_initialize initialize
|
32
32
|
alias zbxapi_do_request do_request
|
33
33
|
|
34
|
+
attr_accessor :major, :minor
|
35
|
+
|
34
36
|
def initialize(url,debug_level=0)
|
35
37
|
@env = env
|
36
38
|
zbxapi_initialize(url,debug_level)
|
@@ -94,6 +96,13 @@ class ZabbixServer
|
|
94
96
|
puts "#{@server_url} connected" if env["echo"]
|
95
97
|
puts "API Version: #{@version}" if env["echo"]
|
96
98
|
|
99
|
+
if env["session_file"] && !env["session_file"].empty?
|
100
|
+
path=File.expand_path(env["session_file"])
|
101
|
+
File.open(path,"w") do |f|
|
102
|
+
f.write({"auth"=>@connection.auth}.to_yaml)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
97
106
|
end
|
98
107
|
|
99
108
|
def logout
|
@@ -111,6 +120,20 @@ class ZabbixServer
|
|
111
120
|
end
|
112
121
|
end
|
113
122
|
|
123
|
+
def use_auth(auth)
|
124
|
+
@server_url = @server_url.nil? ? env["server"] : @server_url
|
125
|
+
|
126
|
+
@connection = ZabbixServer_overload.new(@server_url,env["debug"])
|
127
|
+
@connection.auth=auth
|
128
|
+
major,minor=@connection.do_request(@connection.json_obj('APIInfo.version',{}))['result'].split('.')
|
129
|
+
@connection.major=major.to_i
|
130
|
+
@connection.minor=minor.to_i
|
131
|
+
@version=@connection.API_version
|
132
|
+
@connected=true
|
133
|
+
|
134
|
+
true
|
135
|
+
end
|
136
|
+
|
114
137
|
def loggedin?
|
115
138
|
@connected
|
116
139
|
end
|
data/libs/zabcon_commands.rb
CHANGED
@@ -82,6 +82,11 @@ end
|
|
82
82
|
ZabconCommand.add_command "logout" do
|
83
83
|
set_method do
|
84
84
|
server.logout
|
85
|
+
path=File.expand_path(env["session_file"])
|
86
|
+
begin
|
87
|
+
File.delete(path)
|
88
|
+
rescue Errno::ENOENT
|
89
|
+
end
|
85
90
|
end
|
86
91
|
set_help_tag :logout
|
87
92
|
end
|
@@ -408,7 +413,8 @@ end
|
|
408
413
|
|
409
414
|
ZabconCommand.add_command "add host group" do
|
410
415
|
set_method do |params|
|
411
|
-
server.connection.hostgroup.create(params)
|
416
|
+
groupid = server.connection.hostgroup.create(params)
|
417
|
+
"Created host groupid: #{groupid["groupids"]}"
|
412
418
|
end
|
413
419
|
set_flag :login_required
|
414
420
|
set_flag :print_output
|
@@ -519,7 +525,7 @@ ZabconCommand.add_command "delete user" do
|
|
519
525
|
else
|
520
526
|
id=params["id"]
|
521
527
|
end
|
522
|
-
result
|
528
|
+
result=server.connection.user.delete(id)
|
523
529
|
|
524
530
|
if !result.empty?
|
525
531
|
puts "Deleted user id #{result["userids"]}"
|
@@ -564,7 +570,7 @@ ZabconCommand.add_command "update user" do
|
|
564
570
|
elsif parameters["userid"].nil?
|
565
571
|
puts "Missing required userid statement."
|
566
572
|
end
|
567
|
-
|
573
|
+
server.connection.user.update([parameters])
|
568
574
|
end
|
569
575
|
end
|
570
576
|
set_valid_args 'userid','name', 'surname', 'alias', 'passwd', 'url',
|
data/libs/zabcon_core.rb
CHANGED
@@ -60,7 +60,25 @@ class ZabconCore
|
|
60
60
|
#TODO Remove reference to ArgumentProcessor when new command objects in use
|
61
61
|
debug(5,:msg=>"Setting up ArgumentProcessor")
|
62
62
|
|
63
|
-
|
63
|
+
loaded_session=false
|
64
|
+
begin
|
65
|
+
if !env["server"].nil? && !env["session_file"].nil? &&
|
66
|
+
!env["session_file"].empty?
|
67
|
+
path=File.expand_path(env["session_file"])
|
68
|
+
puts "Attempting to load previous session key from #{env["session_file"]}" if env["echo"]
|
69
|
+
yaml=YAML::load(File.open(path))
|
70
|
+
loaded_session=ZabbixServer.instance.use_auth(yaml["auth"])
|
71
|
+
puts "#{env["server"]} connected" if env["echo"]
|
72
|
+
puts "API Version: #{ZabbixServer.instance.version}" if env["echo"]
|
73
|
+
end
|
74
|
+
rescue Errno::ENOENT
|
75
|
+
puts "Failed to load previous session key" if env["echo"]
|
76
|
+
rescue ZbxAPI_ExceptionLoginPermission
|
77
|
+
puts "Failed to load previous session key" if env["echo"]
|
78
|
+
end
|
79
|
+
|
80
|
+
if !loaded_session && !env["server"].nil? &&
|
81
|
+
!env["username"].nil? && !env["password"].nil?
|
64
82
|
puts "Found valid login credentials, attempting login" if env["echo"]
|
65
83
|
begin
|
66
84
|
ZabbixServer.instance.login
|
data/revision_information
CHANGED
@@ -22,4 +22,8 @@
|
|
22
22
|
* Added deprecate_function to Command class
|
23
23
|
Will show a warning message with new function name to use along with
|
24
24
|
command file path and line numbers/command name
|
25
|
-
* Fixed Ruby version check for 1.9.x
|
25
|
+
* Fixed Ruby version check for 1.9.x
|
26
|
+
* Added session loading. Zabcon will save the auth key upon login to a file
|
27
|
+
which is determined by the config file option "session_file". When starting
|
28
|
+
this file is interrogated if an auth key is found, Zabcon will try to use it.
|
29
|
+
If the auth key does not work it continues with the normal startup sequence.
|
data/zabcon.conf.default
CHANGED
@@ -8,6 +8,12 @@ password=zabbix
|
|
8
8
|
# Set the debug level. 0=off
|
9
9
|
#debug=0
|
10
10
|
|
11
|
+
#Where will the login session information be stored.
|
12
|
+
#If a valid session is found, it's credentials will be tried first
|
13
|
+
#thus speeding up the login/connection process.
|
14
|
+
#Leave empty to disable.
|
15
|
+
#session_file=~/zabcon.session
|
16
|
+
|
11
17
|
# Attempt to show help for a bad command.
|
12
18
|
#show_help=false
|
13
19
|
|
data/zabcon.rb
CHANGED
@@ -147,6 +147,12 @@ class ZabconApp
|
|
147
147
|
opts.on("-d", "--debug LEVEL", Integer, "Specify debug level (Overrides config","file)") do |level|
|
148
148
|
@cmd_opts.debug=level
|
149
149
|
end
|
150
|
+
opts.on("-s","--session PATH","Path to the file to store session information.") do |session|
|
151
|
+
@cmd.session_file=session
|
152
|
+
end
|
153
|
+
opts.on("--no-session","Disable checking of the session file on startup") do
|
154
|
+
@cmd.session_file=""
|
155
|
+
end
|
150
156
|
opts.on("-e", "--[no-]echo", "Enable startup echo. Default is on ","for interactive") do |echo|
|
151
157
|
@cmd_opts.echo=echo
|
152
158
|
end
|
@@ -178,6 +184,7 @@ class ZabconApp
|
|
178
184
|
env["load_config"]=true
|
179
185
|
env["truncate_length"]=5000
|
180
186
|
env["custom_commands"]=nil
|
187
|
+
env["session_file"]="~/zabcon.session"
|
181
188
|
|
182
189
|
#output related environment variables
|
183
190
|
env["table_output"]=STDIN.tty? # Is the output a well formatted table, or csv like?
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zabcon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 725
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 357
|
10
|
+
version: 0.0.357
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- A. Nelson
|