Skip to content

Commit

Permalink
add method run_git_init to the datarecipient baseclass, add IGNORE to…
Browse files Browse the repository at this point in the history
… traps which should be completely ignored
  • Loading branch information
lausser committed Sep 30, 2024
1 parent 73d5969 commit ca97818
Show file tree
Hide file tree
Showing 12 changed files with 248 additions and 127 deletions.
3 changes: 3 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* 2024-09-30 10.2.2
add method run_git_init to the datarecipient baseclass
add IGNORE to traps which should be completely ignored
* 2024-02-16 10.2.1.3
show the class dump only with --debug
* 2024-02-16 10.2.1.2
Expand Down
36 changes: 36 additions & 0 deletions coshsh/datarecipient.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import io
import re
import logging
from subprocess import Popen, PIPE, STDOUT
import string
import random
import coshsh

logger = logging.getLogger('coshsh')
Expand Down Expand Up @@ -156,3 +159,36 @@ def too_much_delta(self):
if self.max_delta[1] >= 0 and abs(self.delta_services) > self.max_delta[1]:
return True
return False

def run_git_init(self, path):
save_dir = os.getcwd()
os.chdir(path)
print("git init------------------")
process = Popen(["git", "init", "."], stdout=PIPE, stderr=STDOUT, universal_newlines=True)
output, unused_err = process.communicate()
retcode = process.poll()
print(output)
init_file = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(16))
open(init_file, "w").close()
print("git add {}------------------".format(init_file))
process = Popen(["git", "add", init_file], stdout=PIPE, stderr=STDOUT, universal_newlines=True)
output, unused_err = process.communicate()
retcode = process.poll()
print(output)
commitmsg = "initial dummy-commit add"
process = Popen(["git", "commit", "-a", "-m", commitmsg], stdout=PIPE, stderr=STDOUT, universal_newlines=True)
output, unused_err = process.communicate()
retcode = process.poll()
print(output)
print("git rm {}------------------".format(init_file))
process = Popen(["git", "rm", init_file], stdout=PIPE, stderr=STDOUT, universal_newlines=True)
output, unused_err = process.communicate()
retcode = process.poll()
print(output)
commitmsg = "initial dummy-commit rm"
process = Popen(["git", "commit", "-a", "-m", commitmsg], stdout=PIPE, stderr=STDOUT, universal_newlines=True)
output, unused_err = process.communicate()
retcode = process.poll()
print(output)
os.chdir(save_dir)

6 changes: 1 addition & 5 deletions recipes/default/classes/datarecipient_coshsh_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,9 @@ def output(self, filter=None):
self.analyze_output(output)
elif not os.path.exists(self.dynamic_dir + '/.git') and self.recipe_git_init and [p for p in os.environ["PATH"].split(os.pathsep) if os.path.isfile(os.path.join(p, "git"))]:
logger.debug("dynamic_dir will be made a git repository")
self.run_git_init(self.dynamic_dir)
save_dir = os.getcwd()
os.chdir(self.dynamic_dir)
print("git init------------------")
process = Popen(["git", "init", "."], stdout=PIPE, stderr=STDOUT, universal_newlines=True)
output, unused_err = process.communicate()
retcode = process.poll()
print(output)
print("git add------------------")
process = Popen(["git", "add", "--all", "."], stdout=PIPE, stderr=STDOUT, universal_newlines=True)
output, unused_err = process.communicate()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def run(self):


setup(name='coshsh',
version='10.2.1.3',
version='10.2.2',
setup_requires=['wheel'],
description='Coshsh - config generator for monitoring systems',
long_description=open('README.md').read(),
Expand Down
1 change: 1 addition & 0 deletions tests/recipes/test20/data/csv20.e_applicationdetails.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
host_name,name,type,monitoring_type,monitoring_0,monitoring_1
1 change: 1 addition & 0 deletions tests/recipes/test20/data/csv20.e_applications.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
host_name,name,type
1 change: 1 addition & 0 deletions tests/recipes/test20/data/csv20.e_hosts.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
host_name,address,alias
94 changes: 49 additions & 45 deletions tests/recipes/testsnmptt/classes/datasource_snmptt.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,28 +206,30 @@ def read(self, filter=None, objects={}, force=False, **kwargs):
# save the last event if there is one
if last_match:
last_match.append(last_eventtext) # add the format of this match
try:
mib_traps[mib].append({
'name': last_eventname,
'oid': last_oid,
'text': last_eventtext,
'recovers': last_recovers,
'match': last_match,
'nagioslevel': last_nagios,
'nodes': last_nodes,
'matches_nodes': create_matches_nodes(last_nodes),
})
except Exception:
mib_traps[mib] = [{
'name': last_eventname,
'oid': last_oid,
'text': last_eventtext,
'recovers': last_recovers,
'match': last_match,
'nagioslevel': last_nagios,
'nodes': last_nodes,
'matches_nodes': create_matches_nodes(last_nodes),
}]
if last_nagios != -1 and "MODE=IGNORE" not in last_nodes:
# if not HIDDEN
try:
mib_traps[mib].append({
'name': last_eventname,
'oid': last_oid,
'text': last_eventtext,
'recovers': last_recovers,
'match': last_match,
'nagioslevel': last_nagios,
'nodes': last_nodes,
'matches_nodes': create_matches_nodes(last_nodes),
})
except Exception:
mib_traps[mib] = [{
'name': last_eventname,
'oid': last_oid,
'text': last_eventtext,
'recovers': last_recovers,
'match': last_match,
'nagioslevel': last_nagios,
'nodes': last_nodes,
'matches_nodes': create_matches_nodes(last_nodes),
}]
last_eventname = eventname_m.group(1).replace(' ', '')
last_oid = eventname_m.group(2)
last_severity = eventname_m.group(3).upper()
Expand All @@ -252,7 +254,8 @@ def read(self, filter=None, objects={}, force=False, **kwargs):
'CRITICAL': 2,
'UNKNOWN': 3,

'HIDDEN': -1,
'HIDDEN': -1, # better use IGNORE
'IGNORE': -1,
}[last_severity]
except Exception as e:
logger.debug('trap severity %s unknown' % eventname_m.group(3))
Expand All @@ -277,28 +280,29 @@ def read(self, filter=None, objects={}, force=False, **kwargs):
last_nodes.append(nodes_m.group(1))
if last_eventname:
# save the last event if there is one
try:
mib_traps[mib].append({
'name': last_eventname,
'oid': last_oid,
'text': last_eventtext,
'recovers': last_recovers,
'match': last_match,
'nagioslevel': last_nagios,
'nodes': last_nodes,
'matches_nodes': create_matches_nodes(last_nodes),
})
except Exception:
mib_traps[mib] = [{
'name': last_eventname,
'oid': last_oid,
'text': last_eventtext,
'recovers': last_recovers,
'match': last_match,
'nagioslevel': last_nagios,
'nodes': last_nodes,
'matches_nodes': create_matches_nodes(last_nodes),
}]
if last_nagios != -1 and "MODE=IGNORE" not in last_nodes:
try:
mib_traps[mib].append({
'name': last_eventname,
'oid': last_oid,
'text': last_eventtext,
'recovers': last_recovers,
'match': last_match,
'nagioslevel': last_nagios,
'nodes': last_nodes,
'matches_nodes': create_matches_nodes(last_nodes),
})
except Exception:
mib_traps[mib] = [{
'name': last_eventname,
'oid': last_oid,
'text': last_eventtext,
'recovers': last_recovers,
'match': last_match,
'nagioslevel': last_nagios,
'nodes': last_nodes,
'matches_nodes': create_matches_nodes(last_nodes),
}]
try:
logger.debug('mib %s counts %d traps' % (mib, len(mib_traps[mib])))
except Exception as e:
Expand Down
78 changes: 40 additions & 38 deletions tests/recipes/testsnmptt/data/snmptt/PAN-TRAPS-7-MIB.snmptt
Original file line number Diff line number Diff line change
Expand Up @@ -12426,44 +12426,46 @@ EDESC
##
##
##
#EVENT panBFDAdminDownTrap .1.3.6.1.4.1.25461.2.1.3.2.0.3503 "Status Events" Normal
#FORMAT Administrative down $*
#SDESC
#Administrative down
#Variables:
# 1: panReceiveTime
# 2: panSerial
# 3: panHostname
# 4: panEventType
# 5: panEventSubType
# 6: panVsys
# 7: panSeqno
# 8: panActionflags
# 9: panSystemEventId
# 10: panSystemObject
# 11: panSystemModule
# 12: panSystemSeverity
# 13: panSystemDescription
#EDESC
EVENT panBFDAdminDownTrap .1.3.6.1.4.1.25461.2.1.3.2.0.3503 "Status Events" Normal
NODES MODE=IGNORE
FORMAT Administrative down $*
SDESC
Administrative down
Variables:
1: panReceiveTime
2: panSerial
3: panHostname
4: panEventType
5: panEventSubType
6: panVsys
7: panSeqno
8: panActionflags
9: panSystemEventId
10: panSystemObject
11: panSystemModule
12: panSystemSeverity
13: panSystemDescription
EDESC
##
##
##
#EVENT panBFDSessionStateChangeTrap .1.3.6.1.4.1.25461.2.1.3.2.0.3504 "Status Events" Normal
#FORMAT Session state change $*
#SDESC
#Session state change
#Variables:
# 1: panReceiveTime
# 2: panSerial
# 3: panHostname
# 4: panEventType
# 5: panEventSubType
# 6: panVsys
# 7: panSeqno
# 8: panActionflags
# 9: panSystemEventId
# 10: panSystemObject
# 11: panSystemModule
# 12: panSystemSeverity
# 13: panSystemDescription
#EDESC
EVENT panBFDSessionStateChangeTrap .1.3.6.1.4.1.25461.2.1.3.2.0.3504 "Status Events" Normal
NODES MODE=NEG
FORMAT Session state change $*
SDESC
Session state change
Variables:
1: panReceiveTime
2: panSerial
3: panHostname
4: panEventType
5: panEventSubType
6: panVsys
7: panSeqno
8: panActionflags
9: panSystemEventId
10: panSystemObject
11: panSystemModule
12: panSystemSeverity
13: panSystemDescription
EDESC
77 changes: 39 additions & 38 deletions tests/recipes/testsnmptt/data/snmptt/PAN-TRAPS-8-MIB.snmptt
Original file line number Diff line number Diff line change
Expand Up @@ -12426,44 +12426,45 @@ EDESC
##
##
##
#EVENT panBFDAdminDownTrap .1.3.6.1.4.1.25461.2.1.3.2.0.3503 "Status Events" Normal
#FORMAT Administrative down $*
#SDESC
#Administrative down
#Variables:
# 1: panReceiveTime
# 2: panSerial
# 3: panHostname
# 4: panEventType
# 5: panEventSubType
# 6: panVsys
# 7: panSeqno
# 8: panActionflags
# 9: panSystemEventId
# 10: panSystemObject
# 11: panSystemModule
# 12: panSystemSeverity
# 13: panSystemDescription
#EDESC
EVENT panBFDAdminDownTrap .1.3.6.1.4.1.25461.2.1.3.2.0.3503 "Status Events" Normal
FORMAT Administrative down $*
SDESC
Administrative down
Variables:
1: panReceiveTime
2: panSerial
3: panHostname
4: panEventType
5: panEventSubType
6: panVsys
7: panSeqno
8: panActionflags
9: panSystemEventId
10: panSystemObject
11: panSystemModule
12: panSystemSeverity
13: panSystemDescription
EDESC
##
##
##
#EVENT panBFDSessionStateChangeTrap .1.3.6.1.4.1.25461.2.1.3.2.0.3504 "Status Events" Normal
#FORMAT Session state change $*
#SDESC
#Session state change
#Variables:
# 1: panReceiveTime
# 2: panSerial
# 3: panHostname
# 4: panEventType
# 5: panEventSubType
# 6: panVsys
# 7: panSeqno
# 8: panActionflags
# 9: panSystemEventId
# 10: panSystemObject
# 11: panSystemModule
# 12: panSystemSeverity
# 13: panSystemDescription
#EDESC
EVENT panBFDSessionStateChangeTrap .1.3.6.1.4.1.25461.2.1.3.2.0.3504 "Status Events" IGNORE
NODES MODE=NEG
FORMAT Session state change $*
SDESC
Session state change
Variables:
1: panReceiveTime
2: panSerial
3: panHostname
4: panEventType
5: panEventSubType
6: panVsys
7: panSeqno
8: panActionflags
9: panSystemEventId
10: panSystemObject
11: panSystemModule
12: panSystemSeverity
13: panSystemDescription
EDESC
Loading

0 comments on commit ca97818

Please sign in to comment.