def test_email_g02(self):
		""" email_g02 """
		email = {
			"alert": True,
			"from": "*****@*****.**",
			"to": ["*****@*****.**"],
			"server": "1.2.3.4",
			"timeout": 10
		}
		self.maxDiff = None
		e = ml_w_email.set(None, email)
		self.assertTrue(e[0], e[1])
		f = open(os.path.join("running", "email.txt"), "r")
		e = f.readlines()
		f.close()
		if "json" == ml_system.CFG_TYPE:
			self.assertEqual(e, ['{"email-server-1": "", "email-server-2": "9.8.7.6", "domain-name": "test.domain.org", "hostname": "test.host"}'])
		if "jcfg" == ml_system.CFG_TYPE:
			self.assertEqual(e, ['email {\n', '    alert True\n', '    from [email protected]\n', '    to-array {\n', '        to [email protected] #1\n', '    }\n', '    server 1.2.3.4\n', '    timeout 10\n', '}\n'])
Exemple #2
0
    def email(self, **kwargs):
        '''
            snmp email notification setting
            data format from middleware
            (True, {'to': [], 'server': '', 'from': '', 'timeout': 0, 'alert': False})
        '''
        import libs.login
        if False == libs.login.cklogin():
            raise _.HTTPRedirect('/')

        import ml_w_email as wem
        import json
        import libs.tools

        _.response.headers["Content-Type"] = "application/json"
        if "from" in kwargs:
            # for updating setting
            libs.tools.v(kwargs)
            tos = []
            if type(kwargs["to"]).__name__ == "list":
                for v in kwargs["to"]:
                    if len(v) > 0:
                        tos.append(libs.tools.convert(v))
            else:
                if len(kwargs['to']) > 0:
                    tos.append(libs.tools.convert(kwargs['to']))

            res = {'to': tos,
                   'server': libs.tools.convert(kwargs['server']),
                   'from': libs.tools.convert(kwargs['from']),
                   'timeout': int(kwargs['timeout']),
                   'alert': 'alert' in kwargs}

            libs.tools.v(res)

            return json.dumps(wem.set(user = self.getUser(), cfg = res))
        else:
            # for information getter
            return json.dumps(wem.get())
			def run(self):
				e = ml_w_email.set(None, email, threading.RLock())