예제 #1
0
 def test_dict(self):
     ip = Icinga2Parser()
     data = {"test": {"item1": "value1"}}
     constants = ["NodeName", "ZoneName"]
     result = ip.parse(attrs=data, constants=constants)
     #print("Tested dictionaries: " + result)
     self.assertMultiLineEqual(result, 'test = {\n  item1 = "value1"\n}\n')
예제 #2
0
 def test_true(self):
     ip = Icinga2Parser()
     data = {"test": "true"}
     constants = ["NodeName", "ZoneName"]
     result = ip.parse(attrs=data, constants=constants)
     #print("Tested boolean true: " + result)
     self.assertEqual(result, 'test = true\n')
예제 #3
0
 def test_string(self):
     ip = Icinga2Parser()
     data = {"test": "string"}
     constants = ["NodeName", "ZoneName"]
     result = ip.parse(attrs=data, constants=constants)
     #print("Tested string: " + result)
     self.assertEqual(result, 'test = "string"\n')
예제 #4
0
 def test_array(self):
     ip = Icinga2Parser()
     data = {"test": ["item1", "item2", "NodeName"]}
     constants = ["NodeName", "ZoneName"]
     result = ip.parse(attrs=data, constants=constants)
     #print("Tested array: " + result)
     self.assertEqual(result, 'test = [ "item1", "item2", NodeName, ]\n')
예제 #5
0
 def test_numbers(self):
     ip = Icinga2Parser()
     data = {"num1": "3", "num2": "2.5"}
     constants = ["NodeName", "ZoneName", "config"]
     result = ip.parse(attrs=data, constants=constants)
     #print("Tested numbers: " + result)
     self.assertMultiLineEqual(result, 'num1 = 3\nnum2 = 2.5\n')
예제 #6
0
 def test_ignore_rules(self):
     ip = Icinga2Parser()
     data = {"ignore": ["match(hostname.fqdn.com, host.name)"]}
     constants = ["NodeName", "ZoneName", "config"]
     result = ip.parse(attrs=data, constants=constants)
     #print("Tested assign rule: " + result)
     self.assertMultiLineEqual(
         result, 'ignore where match("hostname.fqdn.com", host.name)\n')
예제 #7
0
 def test_math(self):
     ip = Icinga2Parser()
     data = {"math_is_fun": "3 * (value1 -  value2) / 2"}
     constants = ["NodeName", "ZoneName", "config"]
     result = ip.parse(attrs=data, constants=constants)
     #print("Tested math: " + result)
     self.assertMultiLineEqual(
         result, 'math_is_fun = 3 * ("value1" -  "value2") / 2\n')
예제 #8
0
 def test_cust_func(self):
     ip = Icinga2Parser()
     data = {"func": "{{ function_blubber(param1,NodeName) }}"}
     constants = ["NodeName", "ZoneName", "config"]
     result = ip.parse(attrs=data, constants=constants)
     #print("Tested custom functions: " + result)
     self.assertMultiLineEqual(
         result, 'func = {{  function_blubber(param1,NodeName)  }}\n')
예제 #9
0
 def test_timeintervals(self):
     ip = Icinga2Parser()
     data = {"check_interval": "3m", "wrong_interval": "3f"}
     constants = ["NodeName", "ZoneName", "config"]
     result = ip.parse(attrs=data, constants=constants)
     #print("Tested timeintervals: " + result)
     self.assertMultiLineEqual(
         result, 'check_interval = 3m\nwrong_interval = "3f"\n')
예제 #10
0
 def test_rocketsyntax_alt_plus(self):
     ip = Icinga2Parser()
     data = {
         "test": ["+", "item1", "ZoneName"],
     }
     constants = ["NodeName", "ZoneName", "config"]
     result = ip.parse(attrs=data, constants=constants)
     #print("Tested rocketsyntax alt plus: " + result)
     self.assertMultiLineEqual(result, 'test += [ "item1", ZoneName, ]\n')
예제 #11
0
 def test_rocketsyntax_minus(self):
     ip = Icinga2Parser()
     data = {
         "test": "- string",
     }
     constants = ["NodeName", "ZoneName", "config"]
     result = ip.parse(attrs=data, constants=constants)
     #print("Tested rocketsyntax minus: " + result)
     self.assertMultiLineEqual(result, 'test -= "string"\n')
예제 #12
0
 def test_unparsed(self):
     ip = Icinga2Parser()
     data = {
         "test": '-:"test NodeName"',
     }
     constants = ["NodeName", "ZoneName"]
     result = ip.parse(attrs=data, constants=constants)
     #print("Tested Unparsed: " + result)
     self.assertMultiLineEqual(result, 'test = "test NodeName"\n')
예제 #13
0
 def test_function(self):
     ip = Icinga2Parser()
     data = {
         "test": 'match(*prod-sfo*, host.name)',
     }
     constants = ["NodeName", "ZoneName"]
     result = ip.parse(attrs=data, constants=constants)
     #print("Tested Functions: " + result)
     self.assertMultiLineEqual(result,
                               'test = match("*prod-sfo*", host.name)\n')
예제 #14
0
 def test_rocketsyntax_merge_keys(self):
     ip = Icinga2Parser()
     data = {
         "vars": {
             "+": "true",
             "item1": "value1",
         },
     }
     constants = ["NodeName", "ZoneName", "config"]
     result = ip.parse(attrs=data, constants=constants)
     #print("Tested merge keys: " + result)
     self.assertMultiLineEqual(result, 'vars.item1 = "value1"\n')
예제 #15
0
 def test_rocketsyntax_merge_keys_with_const(self):
     ip = Icinga2Parser()
     data = {
         "vars": {
             "+": "true",
             "item2": "value2",
             "item1": "NodeName"
         },
     }
     constants = ["NodeName", "ZoneName", "config"]
     result = ip.parse(attrs=data, constants=constants)
     #print("Tested merge keys with const: " + result)
     self.assertIn(
         result, {
             'vars.item2 = "value2"\nvars.item1 = NodeName\n',
             'vars.item1 = NodeName\nvars.item2 = "value2"\n'
         })