def test_run(self): ncpa_check = nc({}, '/api/cpu/percent/', 'test_host', 'test_service') stdout, returncode = ncpa_check.run() self.assertIsInstance(stdout, unicode) self.assertIsInstance(returncode, unicode) new_check = nc({}, '/invalid/check', 'test_host', 'test_service') stdout, returncode = new_check.run() self.assertIsInstance(stdout, unicode) self.assertIsInstance(returncode, unicode)
def test_run(self): stdout, returncode = self.nc.run() self.assertIsInstance(stdout, unicode) self.assertIsInstance(returncode, unicode) new_check = nc('/invalid/check', 'test_host', 'test_service') stdout, returncode = new_check.run() self.assertIsInstance(stdout, unicode) self.assertIsInstance(returncode, unicode)
def test_run_check(self): api_url = '/api/cpu/percent/' api_args = {'check': '1'} ncpa_check = nc({}, None, None, None) result = ncpa_check.run_check(api_url, api_args) result_json = json.loads(result) self.assertIsInstance(result_json, dict) self.assertIn('value', result_json) self.assertIn('stdout', result_json['value']) self.assertIn('returncode', result_json['value'])
def test_run_powershell_plugin(self): self.config.add_section('plugin directives') abs_plugin_path = os.path.abspath('plugins/') self.config.set('plugin directives', 'plugin_path', abs_plugin_path) self.config.set('plugin directives', '.ps1', 'powershell -ExecutionPolicy Unrestricted -File $plugin_name $plugin_args') plugin = """ param ([string]$a, [int]$b) Write-Host $a exit $b """ self.setup_plugin(abs_plugin_path, 'test.ps1', plugin) ncpa_check = nc(self.config, None, None, None) api_url = '/api/agent/plugin/test.ps1' result = ncpa_check.run_check(api_url, {}) result_json = json.loads(result) self.assertIsInstance(result_json, dict) self.assertIn('value', result_json) self.assertEqual(result_json['value']['stdout'], '') self.assertEqual(result_json['value']['returncode'], 0) api_url = '/api/agent/plugin/test.ps1/Bingo' result = ncpa_check.run_check(api_url, {}) result_json = json.loads(result) self.assertIsInstance(result_json, dict) self.assertIn('value', result_json) self.assertEqual(result_json['value']['stdout'], 'Bingo') self.assertEqual(result_json['value']['returncode'], 0) api_url = '/api/agent/plugin/test.ps1/Bingo/42' result = ncpa_check.run_check(api_url, {}) result_json = json.loads(result) self.assertIsInstance(result_json, dict) self.assertIn('value', result_json) self.assertEqual(result_json['value']['stdout'], 'Bingo') self.assertEqual(result_json['value']['returncode'], 42)
def test_run_shell_plugin(self): self.config.add_section('plugin directives') abs_plugin_path = os.path.abspath('plugins/') self.config.set('plugin directives', 'plugin_path', abs_plugin_path) self.config.set('plugin directives', '.sh', 'sh $plugin_name $plugin_args') plugin = "echo $1; exit $2" self.setup_plugin(abs_plugin_path, 'test.sh', plugin) ncpa_check = nc(self.config, None, None, None) api_url = '/api/agent/plugin/test.sh' result = ncpa_check.run_check(api_url, {}) result_json = json.loads(result) self.assertIsInstance(result_json, dict) self.assertIn('value', result_json) self.assertEqual(result_json['value']['stdout'], '') self.assertEqual(result_json['value']['returncode'], 0) api_url = '/api/agent/plugin/test.sh/Hi There' result = ncpa_check.run_check(api_url, {}) result_json = json.loads(result) self.assertIsInstance(result_json, dict) self.assertIn('value', result_json) self.assertEqual(result_json['value']['stdout'], 'Hi There') self.assertEqual(result_json['value']['returncode'], 0) api_url = '/api/agent/plugin/test.sh/Hi There/42' result = ncpa_check.run_check(api_url, {}) result_json = json.loads(result) self.assertIsInstance(result_json, dict) self.assertIn('value', result_json) self.assertEqual(result_json['value']['stdout'], 'Hi There') self.assertEqual(result_json['value']['returncode'], 42)
def setUp(self): listener.server.listener.config['iconfig'] = {} self.nc = nc('/api/cpu/percent/', 'test_host', 'test_service')