コード例 #1
0
 def report(self, status: int):
     message = cwatcher.Message(service_name='my_service',
                                prefix='',
                                status=status)
     with mock.patch('subprocess.run') as subprocess_run:
         self.beep.report(message)
     return subprocess_run
コード例 #2
0
 def send_passive_check(self, **kwargs):
     message = cwatcher.Message(service_name='my_service',
                                prefix='',
                                **kwargs)
     with mock.patch('jflib.command_watcher.icinga.send_passive_check') as \
             send_passive_check:
         self.icinga.report(message)
     return send_passive_check
コード例 #3
0
 def test_method_report_critical(self):
     message = cwatcher.Message(status=2, service_name='test', body='body')
     with mock.patch('jflib.command_watcher.send_email') as send_email:
         self.email.report(message)
     send_email.assert_called_with(
         body='Host: {}\nUser: {}\nService name: test\n\nbody'.format(
             cwatcher.HOSTNAME, cwatcher.USERNAME),
         from_addr='*****@*****.**',
         smtp_login='******',
         smtp_password='******',
         smtp_server='mail.example.com:587',
         subject='[cwatcher]: TEST CRITICAL',
         to_addr='*****@*****.**',
     )
コード例 #4
0
 def setUp(self):
     process_1 = cwatcher.Process('ls')
     process_2 = cwatcher.Process(['ls', '-a'])
     self.message = cwatcher.Message(
         status=0,
         service_name='service',
         performance_data={
             'value1': 1,
             'value2': 2
         },
         custom_message='Everything ok',
         processes=[process_1, process_2],
         body='A long body text.',
         log_records='1 OK \n2 Warning',
     )
コード例 #5
0
 def test_property_service_name_not_set(self):
     message = cwatcher.Message()
     self.assertEqual(message.service_name, 'service_not_set')
コード例 #6
0
 def test_property_status_not_set(self):
     message = cwatcher.Message()
     self.assertEqual(message.status, 0)
     self.assertEqual(message.status_text, 'OK')