Skip to content

Commit

Permalink
fix None fields in csv
Browse files Browse the repository at this point in the history
  • Loading branch information
lausser committed Apr 8, 2017
1 parent 7527450 commit 5e887a4
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions recipes/default/classes/datasource_csvfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def read(self, filter=None, objects={}, force=False, **kwargs):
for row in hostreader:
row["templates"] = ["generic-host"]
for attr in [k for k in row.keys() if k in ['type', 'os', 'hardware', 'virtual']]:
row[attr] = row[attr].lower()
try:
row[attr] = row[attr].lower()
except Exception:
pass
h = coshsh.host.Host(row)
self.add('hosts', h)

Expand All @@ -75,7 +78,10 @@ def read(self, filter=None, objects={}, force=False, **kwargs):
# name,type,component,version,host_name,check_period
for row in appreader:
for attr in [k for k in row.keys() if k in ['name', 'type', 'component', 'version']]:
row[attr] = row[attr].lower()
try:
row[attr] = row[attr].lower()
except Exception:
pass
if '[' in row['host_name'] or '*' in row['host_name']:
# hostnames can be regular expressions
matching_hosts = [h for h in self.objects['hosts'].keys() if re.match('^('+row['host_name']+')', h)]
Expand Down Expand Up @@ -114,13 +120,7 @@ def read(self, filter=None, objects={}, force=False, **kwargs):
row[attr] = row[attr].lower()
application_id = "%s+%s+%s" % (row["host_name"], row["name"], row["type"])
detail = coshsh.monitoringdetail.MonitoringDetail(row)
if application_id in self.objects['applications']:
self.objects['applications'][application_id].monitoring_details.append(detail)
elif row["host_name"] in self.objects['hosts']:
self.objects['hosts'][row["host_name"]].monitoring_details.append(detail)
else:
logger.info("found a detail %s for an unknown application %s" % (detail, application_id))
raise
self.add('details', detail)

try:
contactgroupreader = csv.DictReader(CommentedFile(open(os.path.join(self.dir, self.name+'_contactgroups.csv'))))
Expand Down

0 comments on commit 5e887a4

Please sign in to comment.