PageRenderTime 31ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/test/test_commands_perfdata.py

https://github.com/sduchesneau/shinken
Python | 100 lines | 49 code | 14 blank | 37 comment | 1 complexity | 13243fa3de320c452add299d6d950b38 MD5 | raw file
  1. #!/usr/bin/env python2.6
  2. #Copyright (C) 2009-2010 :
  3. # Gabes Jean, naparuba@gmail.com
  4. # Gerhard Lausser, Gerhard.Lausser@consol.de
  5. #
  6. #This file is part of Shinken.
  7. #
  8. #Shinken is free software: you can redistribute it and/or modify
  9. #it under the terms of the GNU Affero General Public License as published by
  10. #the Free Software Foundation, either version 3 of the License, or
  11. #(at your option) any later version.
  12. #
  13. #Shinken is distributed in the hope that it will be useful,
  14. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. #GNU Affero General Public License for more details.
  17. #
  18. #You should have received a copy of the GNU Affero General Public License
  19. #along with Shinken. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. # This file is used to test acknowledge of problems
  22. #
  23. #It's ugly I know....
  24. from shinken_test import *
  25. class TestConfig(ShinkenTest):
  26. def setUp(self):
  27. self.setup_with_file('etc/nagios_commands_perfdata.cfg')
  28. def test_service_perfdata_command(self):
  29. self.print_header()
  30. #We want an eventhandelr (the perfdata command) to be put in the actions dict
  31. #after we got a service check
  32. now = time.time()
  33. host = self.sched.hosts.find_by_name("test_host_0")
  34. host.checks_in_progress = []
  35. host.act_depend_of = [] # ignore the router
  36. svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
  37. svc.checks_in_progress = []
  38. svc.act_depend_of = [] # no hostchecks on critical checkresults
  39. #--------------------------------------------------------------
  40. # initialize host/service state
  41. #--------------------------------------------------------------
  42. print "Service perfdata command", svc.__class__.perfdata_command, type(svc.__class__.perfdata_command)
  43. #We do not want to be just a string but a real command
  44. self.assert_(not isinstance(svc.__class__.perfdata_command, str))
  45. print svc.__class__.perfdata_command.__class__.my_type
  46. self.assert_(svc.__class__.perfdata_command.__class__.my_type == 'CommandCall')
  47. self.scheduler_loop(1, [[svc, 0, 'OK | bibi=99%']])
  48. print "Actions", self.sched.actions
  49. self.assert_(self.count_actions() == 1)
  50. #Ok now I disable the perfdata
  51. now = time.time()
  52. cmd = "[%lu] DISABLE_PERFORMANCE_DATA" % now
  53. self.sched.run_external_command(cmd)
  54. self.scheduler_loop(1, [[svc, 0, 'OK | bibi=99%']])
  55. print "Actions", self.sched.actions
  56. self.assert_(self.count_actions() == 0)
  57. def test_host_perfdata_command(self):
  58. #We want an eventhandelr (the perfdata command) to be put in the actions dict
  59. #after we got a service check
  60. now = time.time()
  61. host = self.sched.hosts.find_by_name("test_host_0")
  62. host.checks_in_progress = []
  63. host.act_depend_of = [] # ignore the router
  64. svc = self.sched.services.find_srv_by_name_and_hostname("test_host_0", "test_ok_0")
  65. svc.checks_in_progress = []
  66. svc.act_depend_of = [] # no hostchecks on critical checkresults
  67. #--------------------------------------------------------------
  68. # initialize host/service state
  69. #--------------------------------------------------------------
  70. print "Host perfdata command", host.__class__.perfdata_command, type(host.__class__.perfdata_command)
  71. #We do not want to be just a string but a real command
  72. self.assert_(not isinstance(host.__class__.perfdata_command, str))
  73. print host.__class__.perfdata_command.__class__.my_type
  74. self.assert_(host.__class__.perfdata_command.__class__.my_type == 'CommandCall')
  75. self.scheduler_loop(1, [[host, 0, 'UP | bibi=99%']])
  76. print "Actions", self.sched.actions
  77. self.assert_(self.count_actions() == 1)
  78. #Ok now I disable the perfdata
  79. now = time.time()
  80. cmd = "[%lu] DISABLE_PERFORMANCE_DATA" % now
  81. self.sched.run_external_command(cmd)
  82. self.scheduler_loop(1, [[host, 0, 'UP | bibi=99%']])
  83. print "Actions", self.sched.actions
  84. self.assert_(self.count_actions() == 0)
  85. if __name__ == '__main__':
  86. unittest.main()