Skip to content

Commit

Permalink
NPMD solution version update from 1.0 to 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
varastog committed Feb 9, 2017
1 parent 76e9ee2 commit a7f88fe
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ nxFileInventory:

nxOMSAgentNPMConfig:
rm -rf output/staging; \
VERSION="1.0"; \
VERSION="1.1"; \
PROVIDERS="nxOMSAgentNPMConfig"; \
STAGINGDIR="output/staging/$@/DSCResources"; \
cat Providers/Modules/$@.psd1 | sed "s@<MODULE_VERSION>@$${VERSION}@" > intermediate/Modules/$@.psd1; \
Expand Down
Binary file modified Providers/Modules/NPM/Agent/32/npmd_agent_x32
Binary file not shown.
Binary file modified Providers/Modules/NPM/Agent/64/npmd_agent_x64
Binary file not shown.
21 changes: 18 additions & 3 deletions Providers/Modules/NPM/Plugin/plugin/in_npmd_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def start
@agent_restart_count = 0
@last_npmd_start = nil
start_npmd()
@watch_dog_thread = Thread.new(&method(:watch_dog_wait_for_pet))
@watch_dog_thread = nil
@watch_dog_sync = Mutex.new
@watch_dog_last_pet = Time.new
end
Expand All @@ -106,7 +106,7 @@ def shutdown
kill_all_agent_instances()
@npmdClientSock.close() unless @npmdClientSock.nil?
@npmdClientSock = nil
Thread.kill(@watch_dog_thread)
Thread.kill(@watch_dog_thread) if @watch_dog_thread.is_a?(Thread)
Thread.kill(@server_thread)
File.unlink(@location_unix_endpoint) if File.exist?@location_unix_endpoint
File.unlink(@location_agent_binary) if File.exist?@location_agent_binary and (!@do_purge.nil? and @do_purge)
Expand Down Expand Up @@ -217,7 +217,9 @@ def npmd_reader
_uploadData = _json["DataItems"].reject {|x| x["SubType"] == "ErrorLog"}
_diagLogs = _json["DataItems"].select {|x| x["SubType"] == "ErrorLog"}
_validUploadDataItems = Array.new
_batchTime = Time.now.utc.strftime("%Y-%m-%d %H:%M:%SZ")
_uploadData.each do |item|
item["TimeGenerated"] = _batchTime
if item.key?("SubType")
# Append FQDN to path data
if !@fqdn.nil? and item["SubType"] == "NetworkPath"
Expand Down Expand Up @@ -515,17 +517,24 @@ def send_config
end

# Transform the UI XML configuration to agent configuration
_agentConfig = NPMDConfig::GetAgentConfigFromUIConfig(_uiXml)
_agentConfig, _errorSummary = NPMDConfig::GetAgentConfigFromUIConfig(_uiXml)
if _agentConfig.nil? or _agentConfig == ""
Logger::logWarn "Agent configuration transformation returned empty"
return
end

if _errorSummary.strip != ""
log_error "Configuration drops: #{_errorSummary}"
end

@npmdClientSock.puts _agentConfig
@npmdClientSock.flush
@num_config_sent += 1 unless @num_config_sent.nil?
Logger::logInfo "Configuration file sent to npmd_agent"

# Start the watch dog thread after first config
@watch_dog_thread = Thread.new(&method(:watch_dog_wait_for_pet)) if @watch_dog_thread.nil?

else
Logger::logWarn "NPMD client socket not connected yet!"
end
Expand Down Expand Up @@ -589,6 +598,12 @@ def server_run

def watch_dog_wait_for_pet
_sleepInterval = WATCHDOG_PET_INTERVAL_SECS

# Pet right after first agent configuration is sent
@watch_dog_sync.synchronize do
@watch_dog_last_pet = Time.now
end

loop do
sleep(_sleepInterval)
_diffTime = Time.now
Expand Down
122 changes: 104 additions & 18 deletions Providers/Modules/NPM/Plugin/plugin/npmd_config_lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,64 @@ def getNetMaskString
class AgentConfigCreator
public

# Variables for tracking errors
@@agent_ip_drops = 0
@@agent_drops = 0
@@network_subnet_drops = 0
@@network_drops = 0
@@rule_subnetpair_drops = 0
@@rule_drops = 0

# Strings utilized in drop summary
DROP_IPS = "Agent IPs"
DROP_AGENTS = "Agents"
DROP_SUBNETS = "Network subnets"
DROP_NETWORKS = "Networks"
DROP_SUBNETPAIRS= "Rule subnetpairs"
DROP_RULES = "Rules"

# Reset error checking
def self.resetErrorCheck
@@agent_ip_drops = 0
@@agent_drops = 0
@@network_subnet_drops = 0
@@network_drops = 0
@@rule_subnetpair_drops = 0
@@rule_drops = 0
end

# Generating the error string
def self.getErrorSummary
_agentIpDrops=""
_agentDrops=""
_networkSNDrops=""
_networkDrops=""
_ruleSNPairDrops=""
_ruleDrops=""

if @@agent_ip_drops != 0
_agentIpDrops = "#{DROP_IPS}=#{@@agent_ip_drops}"
end
if @@agent_drops != 0
_agentDrops= "#{DROP_AGENTS}=#{@@agent_drops}"
end
if @@network_subnet_drops != 0
_networkSNDrops = "#{DROP_SUBNETS}=#{@@network_subnet_drops}"
end
if @@network_drops != 0
_networkDrops = "#{DROP_NETWORKS}=#{@@network_drops}"
end
if @@rule_subnetpair_drops != 0
_ruleSNPairDrops = "#{DROP_SUBNETPAIRS}=#{@@rule_subnetpair_drops}"
end
if @@rule_drops != 0
_ruleDrops = "#{DROP_RULES}=#{@@rule_drops}"
end
_str = _agentIpDrops + " " + _agentDrops + " " +
_networkSNDrops + " " + _networkDrops + " " +
_ruleSNPairDrops + " " + _ruleDrops
end

# Only accessible method
def self.createXmlFromUIConfigHash(configHash)
begin
Expand Down Expand Up @@ -126,12 +184,17 @@ def self.createAgentElements(agentArray, maskHash)
_subnetMask = maskHash[ip["SubnetName"]]
if _subnetMask.nil?
Logger::logWarn "Did not find subnet mask for subnet name #{ip["SubnetName"]} in hash", 2*Logger::loop
@@agent_ip_drops += 1
else
_ipConfig.add_attribute("Mask", maskHash[ip["SubnetName"]])
_agent.elements << _ipConfig
end
end
_agents.elements << _agent
if _agent.elements.empty?
@@agent_drops += 1
else
_agents.elements << _agent
end
end
_agents
end
Expand All @@ -145,6 +208,7 @@ def self.createNetworkElements(networkArray, subnetIdHash)
_subnetId = subnetIdHash[sn]
if _subnetId.nil?
Logger::logWarn "Did not find subnet id for subnet name #{sn} in hash", 2*Logger::loop
@@network_subnet_drops += 1
else
_snConfig = REXML::Element.new("Subnet")
_snConfig.add_attribute("ID", subnetIdHash[sn])
Expand All @@ -153,7 +217,11 @@ def self.createNetworkElements(networkArray, subnetIdHash)
_network.elements << _snConfig
end
end
_networks.elements << _network
if _network.elements.empty?
@@network_drops += 1
else
_networks.elements << _network
end
end
_networks
end
Expand All @@ -169,12 +237,20 @@ def self.createActOnElements(actOnArray, subnetIdHash, xmlElemName)
if a["DS"] != "*" and a["DS"] != ""
_dSubnetId = subnetIdHash[a["DS"].to_s]
end
_snPair = REXML::Element.new("SubnetPair")
_snPair.add_attribute("SourceSubnet", _sSubnetId)
_snPair.add_attribute("SourceNetwork", a["SN"])
_snPair.add_attribute("DestSubnet", _dSubnetId)
_snPair.add_attribute("DestNetwork", a["DN"])
_xmlElement.elements << _snPair
if _sSubnetId.nil?
Logger::logWarn "Did not find subnet id for source subnet name #{a["SS"].to_s} in hash", 2*Logger::loop
@@rule_subnetpair_drops += 1
elsif _dSubnetId.nil?
Logger::logWarn "Did not find subnet id for destination subnet name #{a["DS"].to_s} in hash", 2*Logger::loop
@@rule_subnetpair_drops += 1
else
_snPair = REXML::Element.new("SubnetPair")
_snPair.add_attribute("SourceSubnet", _sSubnetId)
_snPair.add_attribute("SourceNetwork", a["SN"])
_snPair.add_attribute("DestSubnet", _dSubnetId)
_snPair.add_attribute("DestNetwork", a["DN"])
_xmlElement.elements << _snPair
end
end
_xmlElement
end
Expand All @@ -186,15 +262,20 @@ def self.createRuleElements(ruleArray, subnetIdHash)
_rule.add_attribute("Name", x["Name"])
_rule.add_attribute("Description", "")
_rule.add_attribute("Protocol", x["Protocol"])
_alertConfig = REXML::Element.new("AlertConfiguration")
_alertConfig.add_element("Loss", {"Threshold" => x["LossThreshold"] })
_alertConfig.add_element("Latency", {"Threshold" => x["LatencyThreshold"]})
_netTestMtx = createActOnElements(x["Rules"], subnetIdHash, "NetworkTestMatrix")
_exceptions = createActOnElements(x["Exceptions"], subnetIdHash, "Exceptions")
_rule.elements << _alertConfig
_rule.elements << _netTestMtx
_rule.elements << _exceptions
_rules.elements << _rule
if _netTestMtx.elements.empty?
Logger::logWarn "Skipping rule #{x["Name"]} as network test matrix is empty", Logger::loop
@@rule_drops += 1
else
_alertConfig = REXML::Element.new("AlertConfiguration")
_alertConfig.add_element("Loss", {"Threshold" => x["LossThreshold"] })
_alertConfig.add_element("Latency", {"Threshold" => x["LatencyThreshold"]})
_exceptions = createActOnElements(x["Exceptions"], subnetIdHash, "Exceptions")
_rule.elements << _alertConfig
_rule.elements << _netTestMtx
_rule.elements << _exceptions
_rules.elements << _rule
end
end
_rules
end
Expand Down Expand Up @@ -339,7 +420,10 @@ def self.getRuleHashFromJson(text)
# Only function needed to be called from this module
def self.GetAgentConfigFromUIConfig(uiXml)
_uiHash = UIConfigParser.parse(uiXml)
AgentConfigCreator.resetErrorCheck()
_agentXml = AgentConfigCreator.createXmlFromUIConfigHash(_uiHash)
_errorStr = AgentConfigCreator.getErrorSummary()
return _agentXml, _errorStr
end
end

Expand All @@ -361,7 +445,8 @@ module NPMContract
"PrefixLength",
"AddressType",
"SubType",
"AgentId"]
"AgentId",
"TimeGenerated"]

CONTRACT_PATH_DATA_KEYS = ["SourceNetwork",
"SourceNetworkNodeInterface",
Expand All @@ -383,7 +468,8 @@ module NPMContract
"Loss",
"LossHealthState",
"Path",
"Computer"]
"Computer",
"TimeGenerated"]

CONTRACT_DIAG_DATA_KEYS = ["Message",
"SubType"]
Expand Down

0 comments on commit a7f88fe

Please sign in to comment.