Beispiel #1
0
    def syslog(self, **kwargs):
        '''
            Syslog getter and setter
            format:
            (True, {'server_ip': '192.168.0.1', 'facility': 'local0'})
        '''
        import libs.login
        if False == libs.login.cklogin():
            raise _.HTTPRedirect('/')

        import ml_w_syslog as wsl
        import json
        import libs.tools
        _.response.headers["Content-Type"] = "application/json"
        if "facility" in kwargs:
            # syslog setter
            libs.tools.v(kwargs)
            res = wsl.set(user = self.getUser(), cfg = kwargs)
            if False == res[0]:
                return json.dumps([res[0], libs.tools.translateMessage(res[1])])
            else:
                return json.dumps(res)
            # return json.dumps(wsl.set(user = self.getUser(), cfg = kwargs))
        else:
            # syslog getter
            return json.dumps(wsl.get())
	def test_syslog_g01(self):
		""" syslog_g01 """
		if "json" == ml_system.CFG_TYPE:
			shutil.copyfile(os.path.join("unittest", "syslog-g01.json"), os.path.join("running", "syslog.txt"))
		if "jcfg" == ml_system.CFG_TYPE:
			shutil.copyfile(os.path.join("unittest", "syslog-g01.jcfg"), os.path.join("running", "syslog.txt"))
		if "pickle" == ml_system.CFG_TYPE:
			return
		self.maxDiff = None
		e = ml_w_syslog.get(None, threading.RLock())
		self.assertEqual(e, (True, {
			"server_ip": "192.168.0.1",
			"facility": "local0"
		}))