Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi! I cleaned up your code for you! #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions README.rdoc
Expand Up @@ -23,8 +23,8 @@ few goals:
on Ruby 1.8 standard library & +JSON+ and scripts additionally
depend on +Configliere+[http://github.com/mrflip/configliere].

- Play nicely with Chef[http://www.opscode.com/chef/]
- Play nicely with Chef[http://www.opscode.com/chef/]

There are a lot of other projects out there that connect Ruby to
Zabbix. Here's a quick list:

Expand All @@ -33,23 +33,23 @@ zabbix[http://github.com/lorieri/zabbix]::

zabbixapi[http://github.com/verm666/zabbixapi]::
Ruby module for work with zabbix api

zabbix-rb[http://github.com/mhat/zabbix-rb]::
send data to zabbix from ruby

zabbix_pusher[http://github.com/iteh/zabbix_pusher]::
zabbix_pusher is a gem to parse zabbix templates and push the data
to the corresponding zabbix server

zabbix-trappers[http://github.com/vzctl/zabbix-trappers]::
Collection of ruby scripts for zabbix trappers

rzabbix[http://github.com/neerfri/rzabbix]::
Zabbix API client for Ruby

zabboard[http://github.com/yammer/zabboard]::
zabbix analytics

zabbix-web[http://github.com/legiar/zabbix-web]::
Zabbix frontend

Expand Down Expand Up @@ -104,7 +104,7 @@ quietly for you:
# Response was an error. Uh oh!
puts response.error_message
end

=== On the command line

Rubix comes with a command line utility +zabbix_api+ which lets you
Expand Down Expand Up @@ -133,7 +133,7 @@ complete with host groups, templates, applications, and so on.
# Now the template -- created templates are empty by default!
template = Rubix::Template.new(:name => "Template_Some_Service")
template.save

# Now the host.
host = Rubix::Host.new(:name => "My Host", :ip => '123.123.123.123', :templates => [template], :host_groups => [host_group])
host.save
Expand Down Expand Up @@ -317,7 +317,7 @@ Chef[http://www.opscode.com/chef/] and so Rubix comes with a
require 'rubix'
require 'net/http'
require 'uri'

class WebserverMonitor < Rubix::ChefMonitor

def webserver
Expand All @@ -327,7 +327,7 @@ Chef[http://www.opscode.com/chef/] and so Rubix comes with a
def uri
URI.parse("http://#{webserver['ec2']['public_hostname']}")
end

def measure
begin
if Net::HTTP.get_response(uri).code.to_i == 200
Expand Down
2 changes: 1 addition & 1 deletion lib/rubix.rb
Expand Up @@ -70,5 +70,5 @@ def self.connection
# from being saved by the Zabbix API (i.e. - no host group for a
# host).
ValidationError = Class.new(Error)

end
6 changes: 3 additions & 3 deletions lib/rubix/associations.rb
@@ -1,16 +1,16 @@
module Rubix
module Associations

autoload :HasManyHosts, 'rubix/associations/has_many_hosts'
autoload :HasManyTemplates, 'rubix/associations/has_many_templates'
autoload :HasManyHostGroups, 'rubix/associations/has_many_host_groups'
autoload :HasManyUserMacros, 'rubix/associations/has_many_user_macros'
autoload :HasManyApplications, 'rubix/associations/has_many_applications'
autoload :HasManyItems, 'rubix/associations/has_many_items'

autoload :BelongsToHost, 'rubix/associations/belongs_to_host'
autoload :BelongsToTemplate, 'rubix/associations/belongs_to_template'

end
end

2 changes: 1 addition & 1 deletion lib/rubix/associations/belongs_to_host.rb
Expand Up @@ -30,4 +30,4 @@ def host_id
end
end


2 changes: 1 addition & 1 deletion lib/rubix/associations/belongs_to_template.rb
Expand Up @@ -30,4 +30,4 @@ def template_id
end
end


10 changes: 5 additions & 5 deletions lib/rubix/associations/has_many_applications.rb
@@ -1,13 +1,13 @@
module Rubix
module Associations
module HasManyApplications

def applications= hs
return unless hs
@applications = hs
@application_ids = hs.map(&:id)
end

def applications
return @applications if @applications
return unless @application_ids
Expand All @@ -18,15 +18,15 @@ def application_ids= aids
return unless aids
@application_ids = aids
end

def application_ids
return @application_ids if @application_ids
return unless @applications
@application_ids = @applications.map(&:id)
end

end
end
end


10 changes: 5 additions & 5 deletions lib/rubix/associations/has_many_host_groups.rb
@@ -1,13 +1,13 @@
module Rubix
module Associations
module HasManyHostGroups

def host_groups= hs
return unless hs
@host_groups = hs
@host_group_ids = hs.map(&:id)
end

def host_groups
return @host_groups if @host_groups
return unless @host_group_ids
Expand All @@ -18,7 +18,7 @@ def host_group_ids= hgids
return unless hgids
@host_group_ids = hgids
end

def host_group_ids
return @host_group_ids if @host_group_ids
return unless @host_groups
Expand All @@ -29,9 +29,9 @@ def host_group_params
return [] unless host_group_ids
host_group_ids.map { |hid| { 'groupid' => hid } }
end

end
end
end


10 changes: 5 additions & 5 deletions lib/rubix/associations/has_many_hosts.rb
@@ -1,13 +1,13 @@
module Rubix
module Associations
module HasManyHosts

def hosts= hs
return unless hs
@hosts = hs
@host_ids = hs.map(&:id)
end

def hosts
return @hosts if @hosts
return unless @host_ids
Expand All @@ -18,15 +18,15 @@ def host_ids= hids
return unless hids
@host_ids = hids
end

def host_ids
return @host_ids if @host_ids
return unless @hosts
@host_ids = @hosts.map(&:id)
end

end
end
end


8 changes: 4 additions & 4 deletions lib/rubix/associations/has_many_items.rb
@@ -1,13 +1,13 @@
module Rubix
module Associations
module HasManyItems

def items= is
return unless is
@items = is
@item_ids = is.map(&:id)
end

def items
return @items if @items
return unless @item_ids
Expand All @@ -18,13 +18,13 @@ def item_ids= iids
return unless iids
@item_ids = iids
end

def item_ids
return @item_ids if @item_ids
return unless @items
@item_ids = @items.map(&:id)
end

end
end
end
10 changes: 5 additions & 5 deletions lib/rubix/associations/has_many_templates.rb
@@ -1,13 +1,13 @@
module Rubix
module Associations
module HasManyTemplates

def templates= hs
return unless hs
@templates = hs
@template_ids = hs.map(&:id)
end

def templates
return @templates if @templates
return unless @template_ids
Expand All @@ -18,7 +18,7 @@ def template_ids= tids
return unless tids
@template_ids = tids
end

def template_ids
return @template_ids if @template_ids
return unless @templates
Expand All @@ -29,9 +29,9 @@ def template_params
return [] unless template_ids
template_ids.map { |tid| { 'templateid' => tid } }
end

end
end
end


10 changes: 5 additions & 5 deletions lib/rubix/associations/has_many_user_macros.rb
@@ -1,13 +1,13 @@
module Rubix
module Associations
module HasManyUserMacros

def user_macros= hs
return unless hs
@user_macros = hs
@user_macro_ids = hs.map(&:id)
end

def user_macros
return @user_macros if @user_macros
return unless @user_macro_ids
Expand All @@ -18,7 +18,7 @@ def user_macro_ids= umids
return unless umids
@user_macro_ids = umids
end

def user_macro_ids
return @user_macro_ids if @user_macro_ids
return unless @user_macros
Expand All @@ -29,9 +29,9 @@ def user_macro_params
return [] unless user_macros
user_macros.map { |um| { 'macro' => um.macro_name, 'value' => um.value } }
end

end
end
end


6 changes: 3 additions & 3 deletions lib/rubix/connection.rb
Expand Up @@ -32,7 +32,7 @@ class Connection

# @return [Rubix::Response] the last response from the Zabbix API -- useful for logging purposes
attr_reader :last_response

# Set up a connection to a Zabbix API.
#
# The +uri_or_string+ can be either a string or a <tt>URI</tt>
Expand Down Expand Up @@ -76,7 +76,7 @@ def request method, params
send_raw_request(raw_params)
end
end

# Has this connection already been authorized and provided with a
# authorization token from the Zabbix API?
def authorized?
Expand Down Expand Up @@ -162,7 +162,7 @@ def send_raw_request raw_params
end
raw_response
end

# Generate the raw POST request to send to the Zabbix API
#
# @param [Hash, #to_json] raw_params the complete parameters of the request.
Expand Down
4 changes: 2 additions & 2 deletions lib/rubix/log.rb
Expand Up @@ -45,7 +45,7 @@ def self.default_log_severity
else
severity_name = 'info'
end

begin
return Logger.const_get(severity_name.upcase)
rescue NameError => e
Expand Down Expand Up @@ -117,6 +117,6 @@ def fatal *args
return unless Rubix.logger
Rubix.logger.log(Logger::FATAL, args.join(' '))
end

end
end