Skip to content

Commit

Permalink
18586 add function to register sensors in proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
dcastro-redBorder committed Sep 11, 2024
1 parent 548360e commit 2994471
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
8 changes: 7 additions & 1 deletion resources/libraries/rbmonitor_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ def update_config(resource)
update_cluster_config(resource)
update_service_config(resource)
update_manager_config(resource)
update_sensor_config(resource)
# Probably not super reliable but it's what I have atm
puts "PEDRO RESOURCE #{resource}"
if resource['managers'] && !resource['managers'].empty?
update_sensor_config(resource)
else
update_sensor_proxyips(resource)
end

node.default['redborder']['monitor']['config']['conf'] = {
'debug': log_level,
Expand Down
83 changes: 83 additions & 0 deletions resources/libraries/update_sensor_proxyips.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
module Rbmonitor
module Helpers
def update_sensor_proxyips(resource)
# SENSOR MONITORIZATION FOR PROXY AND IPS
# This is a BAD solution but I'm on a time constraint
# So please, merge this file with update_sensor_config.rb when possible

# FLOW SENSORS
flow_nodes = resource['flow_nodes']
begin
if flow_nodes
# Title of section
node.default['redborder']['monitor']['config']['sensors'].push('/* REMOTE SENSORS */')

flow_nodes.each do |fnode|
next unless !fnode['redborder']['monitors'].empty? && fnode['ipaddress']

fnode_name = fnode['rbname'] || fnode.name
fnode_count = fnode['redborder']['monitors']&.size || 0

if fnode['redborder'] && !fnode['redborder']['monitors'].empty?
# Title of sensor
node.default['redborder']['monitor']['config']['sensors'].push("/* Node: #{fnode_name} Monitors: #{fnode_count} */")
sensor = {
'timeout': 5,
'sensor_name': fnode_name,
'sensor_ip': fnode['ipaddress'],
'community': (fnode['redborder']['snmp_community'].nil? || fnode['redborder']['snmp_community'] == '') ? 'public' : fnode['redborder']['snmp_community'].to_s,
'snmp_version' => (fnode['redborder']['snmp_version'].nil? || fnode['redborder']['snmp_version'] == '') ? '2c' : fnode['redborder']['snmp_version'].to_s,
'enrichment' => enrich(fnode),
'monitors' => monitors(fnode),
}
node.default['redborder']['monitor']['count'] = node.default['redborder']['monitor']['count'] + fnode['redborder']['monitors'].length
node.default['redborder']['monitor']['config']['sensors'].push(sensor)
else
# The sensor is registered in another manager
node.default['redborder']['monitor']['config']['sensors'].push("/* Node: #{fnode_name} Monitors: #{fnode_count} (not in this manager) */")
end
end
end
rescue
puts 'Cant access to flow sensor, skipping...'
end

# DEVICES SENSORS
device_nodes = resource['device_nodes']
begin
if device_nodes
# Title of section
node.default['redborder']['monitor']['config']['sensors'].push('/* DEVICE SENSORS */')

device_nodes.each do |dnode|
next unless !dnode['redborder']['monitors'].empty? && dnode['ipaddress']

dnode_name = dnode['rbname'] || dnode.name
dnode_count = dnode['redborder']['monitors'].size

if dnode['redborder'] && !dnode['redborder']['monitors'].empty?
# Title of sensor
node.default['redborder']['monitor']['config']['sensors'].push("/* Node: #{dnode_name} Monitors: #{dnode_count} */")
sensor = {
'timeout': 5,
'sensor_name': dnode_name,
'sensor_ip': dnode['ipaddress'],
'community': (dnode['redborder']['snmp_community'].nil? || dnode['redborder']['snmp_community'] == '') ? 'public' : dnode['redborder']['snmp_community'].to_s,
'snmp_version': (dnode['redborder']['snmp_version'].nil? || dnode['redborder']['snmp_version'] == '') ? '2c' : dnode['redborder']['snmp_version'].to_s,
'enrichment' => enrich(dnode),
'monitors' => monitors(dnode),
}
node.default['redborder']['monitor']['count'] = node.default['redborder']['monitor']['count'] + dnode['redborder']['monitors'].length
node.default['redborder']['monitor']['config']['sensors'].push(sensor)
else
# The sensor is registered in another manager
node.default['redborder']['monitor']['config']['sensors'].push("/* Node: #{dnode_name} Monitors: #{dnode_count} (not in this manager) */")
end
end
end
rescue
puts 'Cant access to device sensor, skipping...'
end
end
end
end

0 comments on commit 2994471

Please sign in to comment.