Revision 300c8b44
Added by Ohad Levy over 14 years ago
- ID 300c8b4459d11328735fee7558a65e49767b9b02
app/models/host.rb | ||
---|---|---|
self.save
|
||
end
|
||
|
||
# counts each association of a given host
|
||
# e.g. how many hosts belongs to each os
|
||
# returns sorted hash
|
||
def self.count_distribution assocication
|
||
output = {}
|
||
count(:group => assocication).each {|k,v| output[k.to_label] = v unless v == 0 }
|
||
output
|
||
end
|
||
|
||
# counts each association of a given host for HABTM relationships
|
||
# TODO: Merge these two into one method
|
||
# e.g. how many hosts belongs to each os
|
||
# returns sorted hash
|
||
def self.count_habtm assocication
|
||
output = {}
|
||
Host.count(:include => assocication.pluralize, :group => "#{assocication}_id").to_a.each do |a|
|
||
#Ugly Ugly Ugly - I guess I'm missing something basic here
|
||
label = eval(assocication.camelize).send("find",a[0].to_i).to_label if a[0]
|
||
output[label] = a[1]
|
||
end
|
||
output
|
||
end
|
||
|
||
|
||
private
|
||
# align common mac and ip address input
|
||
def normalize_addresses
|
Also available in: Unified diff
fixes #89 - this adds basic graphs and charts for your inventory, it
also includes minor changes to the dashboard graphs