Skip to content

Commit

Permalink
Merge pull request #151 from redBorder/development
Browse files Browse the repository at this point in the history
Release 1.9.3
  • Loading branch information
manegron authored Jun 11, 2024
2 parents 8c03da6 + 88c7af8 commit 20cb1ee
Show file tree
Hide file tree
Showing 26 changed files with 1,019 additions and 881 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
cookbook-rb-manager CHANGELOG
===============

## 1.9.3

- Miguel Negrón
- [a12be85] Improvement/fix lint (#148)

## 1.9.2

- Miguel Negrón
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# manager Cookbook
# cookbook-rb-manager
[![Build Status][build-shield]][build-url]
[![Linters][linters-shield]][linters-url]
[![License][license-shield]][license-url]
Expand Down
390 changes: 191 additions & 199 deletions resources/attributes/default.rb

Large diffs are not rendered by default.

13 changes: 4 additions & 9 deletions resources/libraries/get_all_flow_sensors_info.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
module Rb_manager
module RbManager
module Helpers
def get_all_flow_sensors_info()
def get_all_flow_sensors_info
sensors_info = {}
sensor_types = ["flow-sensor"]

sensor_types = ['flow-sensor']
sensor_types.each do |s_type|
sensors = search(:node, "role:#{s_type}").sort

sensors_info[s_type] = []
sensors.each do |s|
sensors_info[s_type] << s
end
sensors.each { |s| sensors_info[s_type] << s }
end
sensors_info
end
end
end

33 changes: 15 additions & 18 deletions resources/libraries/get_cluster_info.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
module Rb_manager
module RbManager
module Helpers
def get_cluster_info()
def get_cluster_info
cluster_info = {}
manager_nodes = {}

manager_nodes = search(:node, "recipes:rb-manager").sort
manager_nodes = search(:node, 'recipes:rb-manager').sort

#The search function above is looking for rb-manager value in "Recipes" key instead run_list, for this reason
#in the first execution the node data is not added to managers hash, so it will be checked now and added
#to managers array
if !cluster_info.key?(node.name) and node.recipe?("rb-manager") and !manager_nodes.include?(node)
# The search function above is looking for rb-manager value in 'Recipes' key instead run_list, for this reason
# in the first execution the node data is not added to managers hash, so it will be checked now and added
# to managers array
if !cluster_info.key?(node.name) && node.recipe?('rb-manager') && !manager_nodes.include?(node)
manager_nodes << node
end

manager_nodes.each do |mnode|
name = mnode.name
mnode.normal["rb_time"]=Time.now.to_i if mnode["rb_time"].nil?
rb_time = mnode["rb_time"]
mnode.normal['rb_time'] = Time.now.to_i if mnode['rb_time'].nil?
rb_time = mnode['rb_time']
services = []
# add active services to array
mnode_services = mnode["redborder"]["services"].to_h
mnode_services = mnode['redborder']['services'].to_h
mnode_services.each do |service, service_status|
services << service if service_status
end
cluster_info[name] = {}
cluster_info[name]["name"] = name
cluster_info[name]["ip"] = mnode["ipaddress"]
cluster_info[name]["rb_time"] = rb_time
cluster_info[name]["services"] = services
cluster_info[name]['name'] = name
cluster_info[name]['ip'] = mnode['ipaddress']
cluster_info[name]['rb_time'] = rb_time
cluster_info[name]['services'] = services
end

cluster_info = cluster_info.sort{|a,b| (a[1]["rb_time"]||999999999999999999999) <=> (b[1]["rb_time"]||999999999999999999999)}.to_h
return cluster_info
cluster_info = cluster_info.sort { |a, b| (a[1]['rb_time'] || 999999999999999999999) <=> (b[1]['rb_time'] || 999999999999999999999) }.to_h
end
end
end
18 changes: 7 additions & 11 deletions resources/libraries/get_elasticache_nodes.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
module Rb_manager
module RbManager
module Helpers

require 'timeout'
require 'socket'

def getElasticacheNodes(config_endpoint, port)
begin
socket = TCPSocket.new config_endpoint, port
response = []
status = Timeout::timeout(2) {
Timeout.timeout(2) do
finish = true
socket.puts("config get cluster")
socket.puts('config get cluster')
while finish
response.push(socket.gets.chomp)
finish = false if "#{response.last}" == "END"
finish = false if response.last == 'END'
end
}
end
socket.close
nodes = response.at(2).split(" ").map {
|server|
server.split("|").at(0)
}
return nodes

response.at(2).split(' ').map { |server| server.split('|').at(0) }
rescue => e
Chef::Log.error(e.message)
end
Expand Down
15 changes: 8 additions & 7 deletions resources/libraries/get_managers_all.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Rb_manager
module RbManager
module Helpers
def get_managers_all
managers = []
Expand All @@ -15,13 +15,14 @@ def get_managers_all
roles = []
end
end
unless roles.nil?
if roles.include?("manager")
managers << m
end
end
next unless roles.nil?

next unless roles.include?('manager')

managers << m
end

managers
end
end
end
end
13 changes: 7 additions & 6 deletions resources/libraries/get_namespaces.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module Rb_manager
module RbManager
module Helpers
def get_namespaces
namespaces = []
Chef::Role.list.keys.each do |rol|
Chef::Role.list.each_key do |rol|
ro = Chef::Role.load rol
if ro and ro.override_attributes["redborder"] and ro.override_attributes["redborder"]["namespace"] and ro.override_attributes["redborder"]["namespace_uuid"] and !ro.override_attributes["redborder"]["namespace_uuid"].empty?
namespaces.push(ro.override_attributes["redborder"]["namespace_uuid"])
end
next unless ro && ro.override_attributes['redborder'] && ro.override_attributes['redborder']['namespace'] && ro.override_attributes['redborder']['namespace_uuid'] && !ro.override_attributes['redborder']['namespace_uuid'].empty?

namespaces.push(ro.override_attributes['redborder']['namespace_uuid'])
end

namespaces.uniq
end
end
end
end
15 changes: 6 additions & 9 deletions resources/libraries/get_orgs.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
module Rb_manager
module RbManager
module Helpers
def get_orgs()

def get_orgs
organizations = []

Chef::Role.list.keys.each do |m_key|
Chef::Role.list.each_key do |m_key|
m = Chef::Role.load m_key
if !m.override_attributes["redborder"].nil? and !m.override_attributes["redborder"]["organization_uuid"].nil? and m.override_attributes["redborder"]["sensor_uuid"] == m.override_attributes["redborder"]["organization_uuid"]
organizations << m
end
next unless m.override_attributes['redborder'] && m.override_attributes['redborder']['organization_uuid'] && m.override_attributes['redborder']['sensor_uuid'] == m.override_attributes['redborder']['organization_uuid']

organizations << m
end

organizations

end
end
end

43 changes: 21 additions & 22 deletions resources/libraries/get_pipelines.rb
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
module Rb_manager
module RbManager
module Helpers

def get_pipelines()
def get_pipelines
logstash_pipelines = []
sensors = node.run_state["sensors_info_all"]
sensors = node.run_state['sensors_info_all']
namespaces = get_namespaces()
main_logstash = determine_main_logstash_node()

if manager_services["logstash"]
logstash_pipelines.push("rbwindow-pipeline") if main_logstash == node.name
logstash_pipelines.push("apstate-pipeline")
logstash_pipelines.push("scanner-pipeline") unless sensors["scanner-sensor"].empty?
logstash_pipelines.push("nmsp-pipeline") if main_logstash == node.name and !sensors["flow-sensor"].empty?
logstash_pipelines.push("radius-pipeline") if main_logstash == node.name
logstash_pipelines.push("vault-pipeline") unless sensors["vault-sensor"].empty?
logstash_pipelines.push("netflow-pipeline") unless sensors["flow-sensor"].empty?
logstash_pipelines.push("sflow-pipeline") unless sensors["flow-sensor"].empty?
logstash_pipelines.push("meraki-pipeline") unless sensors["meraki-sensor"].empty?
logstash_pipelines.push("monitor-pipeline") unless namespaces.empty?
logstash_pipelines.push("location-pipeline") unless sensors["ale-sensor"].empty? or sensors["mse-sensor"].empty? or sensors["flow-sensor"].empty? or sensors["arubacentral-sensor"].empty?
logstash_pipelines.push("mobility-pipeline")
logstash_pipelines.push("redfish-pipeline") unless sensors["device-sensor"].empty?
logstash_pipelines.push("bulkstats-pipeline") unless sensors["device-sensor"].empty?
if manager_services['logstash']
logstash_pipelines.push('rbwindow-pipeline') if main_logstash == node.name
logstash_pipelines.push('apstate-pipeline')
logstash_pipelines.push('scanner-pipeline') unless sensors['scanner-sensor'].empty?
logstash_pipelines.push('nmsp-pipeline') if main_logstash == node.name && !sensors['flow-sensor'].empty?
logstash_pipelines.push('radius-pipeline') if main_logstash == node.name
logstash_pipelines.push('vault-pipeline') unless sensors['vault-sensor'].empty?
logstash_pipelines.push('netflow-pipeline') unless sensors['flow-sensor'].empty?
logstash_pipelines.push('sflow-pipeline') unless sensors['flow-sensor'].empty?
logstash_pipelines.push('meraki-pipeline') unless sensors['meraki-sensor'].empty?
logstash_pipelines.push('monitor-pipeline') unless namespaces.empty?
logstash_pipelines.push('location-pipeline') unless sensors['ale-sensor'].empty? || sensors['mse-sensor'].empty? || sensors['flow-sensor'].empty? || sensors['arubacentral-sensor'].empty?
logstash_pipelines.push('mobility-pipeline')
logstash_pipelines.push('redfish-pipeline') unless sensors['device-sensor'].empty?
logstash_pipelines.push('bulkstats-pipeline') unless sensors['device-sensor'].empty?
end
logstash_pipelines
end

# The main logstash is a node where both memcached and logstash are running or the first logstash node (order by name).
# This main logasths node is gonna run the pipelines rbwindow, location, mobility, nmsp, meraki and radius
# Those pipelines should only run in one node (the main_logstash node) for now..
def determine_main_logstash_node()
memcached_nodes = managers_per_service["memcached"].sort.uniq
logstash_nodes = managers_per_service["logstash"].sort.uniq
def determine_main_logstash_node
memcached_nodes = managers_per_service['memcached'].sort.uniq
logstash_nodes = managers_per_service['logstash'].sort.uniq
main_logstash_nodes = memcached_nodes & logstash_nodes
main_logstash_nodes.first || logstash_nodes.first
end
Expand Down
13 changes: 6 additions & 7 deletions resources/libraries/get_sensors_all_info.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
module Rb_manager
module RbManager
module Helpers
def get_sensors_all_info()
def get_sensors_all_info
sensors_info = {}
sensor_types = ["ips-sensor","ipsv2-sensor","ipscp-sensor","ipsg-sensor","vault-sensor","flow-sensor","arubacentral-sensor","mse-sensor","meraki-sensor","cisco-cloudproxy","proxy-sensor","scanner-sensor","mse-sensor","meraki-sensor","ale-sensor","cep-sensor","device-sensor"]
sensor_types = %w(ips-sensor ipsv2-sensor ipscp-sensor ipsg-sensor vault-sensor flow-sensor arubacentral-sensor mse-sensor meraki-sensor cisco-cloudproxy proxy-sensor scanner-sensor mse-sensor meraki-sensor ale-sensor cep-sensor device-sensor)

sensor_types.each do |s_type|
sensors = search(:node, "role:#{s_type} AND -redborder_parent_id:*?").sort #get sensor where parent_id is nil
sensors = search(:node, "role:#{s_type} AND -redborder_parent_id:*?").sort # get sensor where parent_id is nil

sensors_info[s_type] = []
sensors.each do |s|
sensors_info[s_type] << s
end
sensors.each { |s| sensors_info[s_type] << s }
end

sensors_info
end
end
Expand Down
37 changes: 20 additions & 17 deletions resources/libraries/get_sensors_info.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
module Rb_manager
module RbManager
module Helpers
def get_sensors_info()
def get_sensors_info
sensors_info = {}
sensor_types = %w(vault-sensor flow-sensor mse-sensor scanner-sensor meraki-sensor ale-sensor device-sensor
cisco-cloudproxy proxy-sensor
ips-sensor ipsv2-sensor ipscp-sensor ipsg-sensor)
locations = node["redborder"]["locations"]
locations = node['redborder']['locations']
sensor_types.each do |s_type|
sensors = search(:node, "role:#{s_type} AND -redborder_parent_id:*?").sort #get sensor where parent_id is nil
# get sensor where parent_id is nil
sensors = search(:node, "role:#{s_type} AND -redborder_parent_id:*?").sort
sensors_info[s_type] = {}
sensors.each do |s|
info = {}
info["name"] = s.name
info["ip"] = s["ipaddress"]
info["sensor_uuid"] = s["redborder"]["sensor_uuid"] if !s["redborder"]["sensor_uuid"].nil?
info["organization_uuid"] = s["redborder"]["organization_uuid"] if !s["redborder"]["organization_uuid"].nil?
info["megabytes_limit"] = s["redborder"]["megabytes_limit"] if !s["redborder"]["megabytes_limit"].nil?
info["index_partitions"] = s["redborder"]["index_partitions"] if !s["redborder"]["index_partitions"].nil?
info["index_replicas"] = s["redborder"]["index_replicas"] if !s["redborder"]["index_replicas"].nil?
info["sensors_mapping"] = s["redborder"]["sensors_mapping"] if !s["redborder"]["sensors_mapping"].nil?
info["locations"] = {}
info['name'] = s.name
info['ip'] = s['ipaddress']
info['sensor_uuid'] = s['redborder']['sensor_uuid'] if s['redborder']['sensor_uuid']
info['organization_uuid'] = s['redborder']['organization_uuid'] if s['redborder']['organization_uuid']
info['megabytes_limit'] = s['redborder']['megabytes_limit'] if s['redborder']['megabytes_limit']
info['index_partitions'] = s['redborder']['index_partitions'] if s['redborder']['index_partitions']
info['index_replicas'] = s['redborder']['index_replicas'] if s['redborder']['index_replicas']
info['sensors_mapping'] = s['redborder']['sensors_mapping'] if s['redborder']['sensors_mapping']
info['locations'] = {}

locations.each do |loc|
if !s["redborder"][loc].nil?
info["locations"][loc] = s["redborder"][loc]
end
next unless s['redborder'][loc]

info['locations'][loc] = s['redborder'][loc]
end
sensors_info[s_type][s.name] = info
end
end
return sensors_info

sensors_info
end
end
end
Loading

0 comments on commit 20cb1ee

Please sign in to comment.