code: #!/usr/bin/env python
  # -*- coding: utf-8 -*-
  #
  # Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors
  #
  # This file is part of Alignak.
  #
  # Alignak is free software: you can redistribute it and/or modify
  # it under the terms of the GNU Affero General Public License as published by
  # the Free Software Foundation, either version 3 of the License, or
  # (at your option) any later version.
  #
  # Alignak is distributed in the hope that it will be useful,
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  # GNU Affero General Public License for more details.
  #
  # You should have received a copy of the GNU Affero General Public License
  # along with Alignak.  If not, see <http://www.gnu.org/licenses/>.
  #
  #
  # This file incorporates work covered by the following copyright and
  # permission notice:
  #
  #  Copyright (C) 2009-2014:
  #     Jean Gabes, dummy@email.com
  #     Hartmut Goebel, dummy@email.com
  #     Grégory Starck, dummy@email.com
  #     Zoran Zaric, dummy@email.com
  #     Sebastien Coavoux, dummy@email.com
  
  #  This file is part of Shinken.
  #
  #  Shinken is free software: you can redistribute it and/or modify
  #  it under the terms of the GNU Affero General Public License as published by
  #  the Free Software Foundation, either version 3 of the License, or
  #  (at your option) any later version.
  #
  #  Shinken is distributed in the hope that it will be useful,
  #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  #  GNU Affero General Public License for more details.
  #
  #  You should have received a copy of the GNU Affero General Public License
  #  along with Shinken.  If not, see <http://www.gnu.org/licenses/>.
  
  #
  # This file is used to test reading and processing of config files
  #
  
  from alignak_test import *
  
  
  class TestConfig(AlignakTest):
      def setUp(self):
          self.setup_with_file('etc/alignak_resultmodulation.cfg')
  
      def get_svc(self):
          return self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
  
      def get_host(self):
          return self.sched.hosts.find_by_name("test_host_0")
  
      def get_router(self):
          return self.sched.hosts.find_by_name("test_router_0")
  
      def test_service_resultmodulation(self):
          svc = self.get_svc()
          host = self.get_host()
          router = self.get_router()
  
          self.scheduler_loop(2, [[host, 0, 'UP | value1=1 value2=2'], [svc, 2, 'BAD | value1=0 value2=0'],])
          self.assertEqual('UP', host.state)
          self.assertEqual('HARD', host.state_type)
  
          # This service got a result modulation. So Criticals are in fact
          # Warnings. So even with some CRITICAL (2), it must be warning
          self.assertEqual('WARNING', svc.state)
  
          # If we remove the resultmodulations, we should have theclassic behavior
          svc.resultmodulations = []
          self.scheduler_loop(2, [[host, 0, 'UP | value1=1 value2=2'], [svc, 2, 'BAD | value1=0 value2=0']])
          self.assertEqual('CRITICAL', svc.state)
  
          # Now look for the inheritaed thing
          # resultmodulation is a inplicit inherited parameter
          # and router define it, but not test_router_0/test_ok_0. So this service should also be impacted
          svc2 = self.sched.services.find_srv_by_name_and_hostname("test_router_0", "test_ok_0")
          self.assertEqual(router.resultmodulations, svc2.resultmodulations)
  
          self.scheduler_loop(2, [[svc2, 2, 'BAD | value1=0 value2=0']])
          self.assertEqual('WARNING', svc2.state)
  
  
  if __name__ == '__main__':
      unittest.main()
  
entities: [['EMAIL_ADDRESS', 'dummy@email.com'], ['EMAIL_ADDRESS', 'dummy@email.com'], ['EMAIL_ADDRESS', 'dummy@email.com'], ['EMAIL_ADDRESS', 'dummy@email.com'], ['EMAIL_ADDRESS', 'dummy@email.com'], ['DATE_TIME', '2015-2015'], ['LOCATION', 'Alignak'], ['LOCATION', 'Alignak'], ['LOCATION', 'Alignak'], ['LOCATION', 'Alignak'], ['LOCATION', 'Alignak'], ['DATE_TIME', '2009-2014'], ['PERSON', 'Jean Gabes'], ['PERSON', 'Hartmut Goebel'], ['PERSON', 'Grégory Starck'], ['PERSON', 'Zoran Zaric'], ['PERSON', 'Sebastien Coavoux'], ['PERSON', 'Shinken'], ['PERSON', 'Shinken'], ['PERSON', 'Shinken'], ['PERSON', 'Shinken'], ['PERSON', 'test_service_resultmodulation(self'], ['URL', 'http://www.gnu.org/licenses/'], ['URL', 'http://www.gnu.org/licenses/'], ['URL', 'email.com'], ['URL', 'email.com'], ['URL', 'email.com'], ['URL', 'email.com'], ['URL', 'email.com'], ['URL', 'self.se'], ['URL', 'resultmodulation.cf'], ['URL', 'self.sched.services.fi'], ['URL', 'self.sched.hosts.fi'], ['URL', 'self.sched.hosts.fi'], ['URL', 'self.ge'], ['URL', 'self.ge'], ['URL', 'self.ge'], ['URL', 'self.sc'], ['URL', 'self.as'], ['URL', 'host.st'], ['URL', 'self.as'], ['URL', 'host.st'], ['URL', 'self.as'], ['URL', 'svc.st'], ['URL', 'svc.re'], ['URL', 'self.sc'], ['URL', 'self.as'], ['URL', 'svc.st'], ['URL', 'self.sched.services.fi'], ['URL', 'self.as'], ['URL', 'router.re'], ['URL', 'svc2.re'], ['URL', 'self.sc'], ['URL', 'self.as'], ['URL', 'svc2.st'], ['URL', 'unittest.ma']]