Merge branch 'master' of ssh://lausser,shinken@shinken.git.sourceforge.net/gitroot...
[shinken.git] / test / test_module_simplelog.py
blob92a17a19c6e5e10a42c5f1d463bb35b0acc1e1ca
1 #!/usr/bin/env python2.6
2 #Copyright (C) 2009-2010 :
3 # Gabes Jean, naparuba@gmail.com
4 # Gerhard Lausser, Gerhard.Lausser@consol.de
6 #This file is part of Shinken.
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.
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.
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/>.
23 # This file is used to test reading and processing of config files
26 import os
27 from shinken_test import unittest, ShinkenTest
29 from shinken.brok import Brok
30 from shinken.modules.simplelog_broker import get_instance
33 class TestConfig(ShinkenTest):
34 #setUp is in shinken_test
36 #Change ME :)
37 def test_simplelog(self):
38 print self.conf.modules
39 #get our modules
40 mod = None
41 for m in self.conf.modules:
42 if m.module_type == 'simple_log':
43 mod = m
44 self.assert_(mod is not None)
45 self.assert_(mod.path == 'tmp/nagios.log')
46 self.assert_(mod.module_name == 'Simple-log')
48 try :
49 os.unlink(mod.path)
50 except :
51 pass
53 sl = get_instance(mod)
54 print sl
55 #Hack here :(
56 sl.properties = {}
57 sl.properties['to_queue'] = None
58 sl.init()
59 b = Brok('log', {'log' : "look at my ass.\n"})
60 sl.manage_brok(b)
61 b = Brok('log', {'log' : "look at my ass again.\n"})
62 sl.manage_brok(b)
63 sl.file.close()
64 fd = open(mod.path)
65 buf = fd.readline()
66 self.assert_(buf == "look at my ass.\n")
67 buf = fd.readline()
68 self.assert_(buf == "look at my ass again.\n")
69 fd.close()
70 os.unlink(mod.path)
73 if __name__ == '__main__':
74 unittest.main()