コード例 #1
0
ファイル: testcollector.py プロジェクト: sara62/Diamond
    def test_SetHostnameViaShellCmdWithError(self, patch_time):
        reset_hostname_cache()
        config = configobj.ConfigObj()
        config['server'] = {}
        config['server']['collectors_config_path'] = ''
        config['collectors'] = {}
        config['collectors']['default'] = {
            'hostname': 'exit 1',
            'hostname_method': 'shell',
            'hostname_cache_expiration_interval': '300'
        }
        # Should fail the first time.
        c = Collector(config, [])
        self.assertRaises(CalledProcessError, c.get_hostname)

        # Success
        patch_time.return_value = 0
        config['collectors']['default']['hostname'] = 'echo custom.localhost'
        c = Collector(config, [])
        self.assertEquals('custom.localhost', c.get_hostname())

        # Should NOT fail before the timeout.
        patch_time.return_value = 299
        config['collectors']['default']['hostname'] = 'exit 1'
        c = Collector(config, [])
        self.assertEquals('custom.localhost', c.get_hostname())

        # Should fail again after the timeout.
        patch_time.return_value = 301
        config['collectors']['default']['hostname'] = 'exit 1'
        c = Collector(config, [])
        self.assertRaises(CalledProcessError, c.get_hostname)
コード例 #2
0
ファイル: test.py プロジェクト: steveberryman/Diamond
 def test_SetCustomHostname(self):
     config = configobj.ConfigObj()
     config["server"] = {}
     config["server"]["collectors_config_path"] = ""
     config["collectors"] = {}
     config["collectors"]["default"] = {"hostname": "custom.localhost"}
     c = Collector(config, [])
     self.assertEquals("custom.localhost", c.get_hostname())
コード例 #3
0
 def test_SetCustomHostname(self):
     config = configobj.ConfigObj()
     config['server'] = {}
     config['server']['collectors_config_path'] = ''
     config['collectors'] = {}
     config['collectors']['default'] = {
         'hostname': 'custom.localhost',
     }
     c = Collector(config, [])
     self.assertEquals('custom.localhost', c.get_hostname())
コード例 #4
0
ファイル: test.py プロジェクト: ross/Diamond
 def test_SetCustomHostname(self):
     config = configobj.ConfigObj()
     config['server'] = {}
     config['server']['collectors_config_path'] = ''
     config['collectors'] = {}
     config['collectors']['default'] = {
         'hostname' : 'custom.localhost',
     }
     c = Collector(config, [])
     self.assertEquals('custom.localhost', c.get_hostname())
コード例 #5
0
 def test_SetHostnameViaShellCmd(self):
     config = configobj.ConfigObj()
     config['server'] = {}
     config['server']['collectors_config_path'] = ''
     config['collectors'] = {}
     config['collectors']['default'] = {
         'hostname': 'echo custom.localhost',
         'hostname_method': 'shell',
     }
     c = Collector(config, [])
     self.assertEquals('custom.localhost', c.get_hostname())
コード例 #6
0
ファイル: testcollector.py プロジェクト: AnderEnder/Diamond
 def test_SetHostnameViaShellCmd(self):
     config = configobj.ConfigObj()
     config['server'] = {}
     config['server']['collectors_config_path'] = ''
     config['collectors'] = {}
     config['collectors']['default'] = {
         'hostname': 'echo custom.localhost',
         'hostname_method': 'shell',
     }
     c = Collector(config, [])
     self.assertEquals('custom.localhost', c.get_hostname())
コード例 #7
0
ファイル: testcollector.py プロジェクト: sara62/Diamond
    def test_SetHostnameViaShellCmdWithExpiration(self, patch_time):
        reset_hostname_cache()
        config = configobj.ConfigObj()
        config['server'] = {}
        config['server']['collectors_config_path'] = ''
        config['collectors'] = {}
        config['collectors']['default'] = {
            'hostname': 'echo custom.localhost',
            'hostname_method': 'shell',
            'hostname_cache_expiration_interval': '300'
        }
        patch_time.return_value = 0
        c = Collector(config, [])
        self.assertEquals('custom.localhost', c.get_hostname())

        patch_time.return_value = 100
        config['collectors']['default']['hostname'] = 'echo custom.localhost2'
        c = Collector(config, [])
        self.assertEquals('custom.localhost', c.get_hostname())

        patch_time.return_value = 301
        config['collectors']['default']['hostname'] = 'echo custom.localhost2'
        c = Collector(config, [])
        self.assertEquals('custom.localhost2', c.get_hostname())
コード例 #8
0
ファイル: testcollector.py プロジェクト: sara62/Diamond
    def test_SetHostnameViaShellCmdWithErrorSkipJsonKey(self, patch_time):
        reset_hostname_cache()
        config = configobj.ConfigObj()
        config['server'] = {}
        config['server']['collectors_config_path'] = ''
        config['collectors'] = {}
        config['collectors']['default'] = {
            'hostname': 'exit 1',
            'hostname_method': 'shell',
            'hostname_cache_expiration_interval': '300',
            'hostname_cache_skip_errors': True,
            'shell_json_key': 'test_key'
        }
        # Should fail the first time.
        c = Collector(config, [])
        self.assertRaises(CalledProcessError, c.get_hostname)

        script = 'python -c "import json; print json.dumps({\'test_key\': \'test_value\'})"'

        # Success
        patch_time.return_value = 0
        config['collectors']['default']['hostname'] = script
        c = Collector(config, [])
        self.assertEquals('test_value', c.get_hostname())

        # Should NOT fail before the timeout.
        patch_time.return_value = 299
        config['collectors']['default']['hostname'] = 'exit 1'
        c = Collector(config, [])
        self.assertEquals('test_value', c.get_hostname())

        # Should NOT fail again after the timeout.
        patch_time.return_value = 301
        config['collectors']['default']['hostname'] = 'exit 1'
        c = Collector(config, [])
        self.assertEquals('test_value', c.get_hostname())
コード例 #9
0
ファイル: testcollector.py プロジェクト: sara62/Diamond
    def test_SourceMerge(self):
        reset_hostname_cache()
        config = configobj.ConfigObj()
        config['server'] = {}
        config['server']['collectors_config_path'] = ''
        config['collectors'] = {}
        config['collectors']['default'] = {
            'hostname': 'custom.localhost',
        }
        c = Collector(config, [])
        self.assertEquals('custom.localhost', c.get_hostname())
        self.assertEquals('custom.localhost', c.construct_host(None))
        self.assertEquals('test', c.construct_host('test'))

        config['collectors']['default']['merge_sources'] = True
        c = Collector(config, [])
        self.assertEquals('custom.localhost.test', c.construct_host('test'))

        config['collectors']['default']['merge_sources_separator'] = '!'
        c = Collector(config, [])
        self.assertEquals('custom.localhost!test', c.construct_host('test'))
コード例 #10
0
ファイル: testcollector.py プロジェクト: sara62/Diamond
    def test_SetHostnameViaShellJson(self):
        reset_hostname_cache()
        config = configobj.ConfigObj()
        config['server'] = {}
        config['server']['collectors_config_path'] = ''
        config['collectors'] = {}
        config['collectors']['default'] = {
            'hostname': 'python -c "import json; print json.dumps({\'test_key\': \'test_value\'})"',
            'hostname_method': 'shell',
            'shell_json_key': 'test_key'
        }

        c = Collector(config, [])
        self.assertEquals('test_value', c.get_hostname())

        reset_hostname_cache()
        config['collectors']['default']['shell_json_key'] = 'bad_key'
        c = Collector(config, [])

        self.assertRaisesRegexp(
            DiamondException, 'No value found for shell key', c.get_hostname)
コード例 #11
0
    def test_SubConfigOverridesCollectorsConfig(self):
        temp_dir = tempfile.gettempdir()
        if not temp_dir:
            self.skipTest("No temporary directory in system")
        
        config = configobj.ConfigObj()
        config['server'] = {}
        config['server']['collectors_config_path'] = temp_dir
        config['collectors'] = {}
        config['collectors']['default'] = {}

        
        self.tmpfile = os.path.join(temp_dir, 'Collector.conf')
        collectorConfig = configobj.ConfigObj(self.tmpfile)
        collectorConfig['hostname'] = "Collector.hostname"
        collectorConfig['named instances'] = {}
        collectorConfig['named instances']['Instance B'] = {}
        collectorConfig['named instances']['Instance B']['hostname'] = 'custom.hostname'
        collectorConfig.write()

        c = Collector(config, [], instance_name='Instance B')

        self.assertEquals('custom.hostname', c.get_hostname())