Skip to content

Commit e6d03ba

Browse files
committed
Add default host for empty instances section
1 parent 1ebc62f commit e6d03ba

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/collectors/postgres/postgres.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,18 @@ def collect(self):
102102
self.log.error('Unable to import module psycopg2')
103103
return {}
104104

105-
# Check instances
106-
if self.config['instances'] == {}:
107-
self.log.error("Instances are not configured!")
108-
return {}
109-
110-
for instance in self.config['instances'].keys():
105+
instances = self.config.get('instances')
106+
107+
# HACK: setting default with subcategory messes up merging of configs,
108+
# so we only set the default if one wasn't provided.
109+
if not instances:
110+
instances = {
111+
'default': {
112+
'host': 'localhost',
113+
}
114+
}
115+
116+
for instance in instances:
111117
# Get list of databases
112118
dbs = self._get_db_names(instance)
113119
if len(dbs) == 0:

src/collectors/postgres/test/testpostgres.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ def setUp(self, allowed_names=None):
3838
def test_import(self):
3939
self.assertTrue(PostgresqlCollector)
4040

41-
def test_config_with_empty_instance(self):
42-
result = self.default_collector.collect()
43-
self.assertEqual(result, {})
44-
4541
def test_config_override(self):
4642
self.assertEqual(self.collector._get_config('postgres_a', 'port'), 5432)
4743

0 commit comments

Comments
 (0)