本文整理汇总了Python中toughlib.logger.error函数的典型用法代码示例。如果您正苦于以下问题:Python error函数的具体用法?Python error怎么用?Python error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: load_events
def load_events(event_path=None, pkg_prefix=None, excludes=[], event_params={}):
_excludes = ["__init__", "settings"] + excludes
evs = set(os.path.splitext(it)[0] for it in os.listdir(event_path))
evs = [it for it in evs if it not in _excludes]
for ev in evs:
try:
sub_module = os.path.join(event_path, ev)
if os.path.isdir(sub_module):
# logger.info('load sub event %s' % ev)
load_events(
event_path=sub_module,
pkg_prefix="{0}.{1}".format(pkg_prefix, ev),
excludes=excludes,
event_params=event_params,
)
_ev = "{0}.{1}".format(pkg_prefix, ev)
# logger.info('load_event %s with params:%s' % (_ev,repr(event_params)))
robj = importlib.import_module(_ev)
if hasattr(robj, "evobj"):
dispatch.register(robj.evobj)
if hasattr(robj, "__call__"):
dispatch.register(robj.__call__(**event_params))
except Exception as err:
logger.error("%s, skip module %s.%s" % (str(err), pkg_prefix, ev))
import traceback
traceback.print_exc()
continue
开发者ID:fozzmarc,项目名称:toughlib,代码行数:28,代码来源:permit.py
示例2: disconnect
def disconnect(self):
try:
is_chap=self.settings.config.portal.chap in (1, "1", "chap")
userIp = self.current_user.ipaddr
nas = self.get_nas(self.current_user.nasaddr)
ac_addr = nas['ip_addr']
ac_port = int(nas['ac_port'])
secret = utils.safestr(nas['bas_secret'])
_vendor= utils.safestr(nas['portal_vendor'])
if _vendor not in ('cmccv1','cmccv2','huaweiv1','huaweiv2'):
defer.returnValue("not support vendor %s"%_vendor)
send_portal = functools.partial(
client.send,
secret,
log=self.syslog,
debug=self.settings.debug,
vendor=_vendor
)
vendor = client.PortalClient.vendors.get(_vendor)
logout_req = vendor.proto.newReqLogout(userIp, secret,chap=is_chap)
logout_resp = yield send_portal(data=logout_req, host=ac_addr, port=ac_port)
if logout_resp.errCode > 0:
_err_msg=u"{0},{1}".format(
vendor.mod.AckLogoutErrs[logout_resp.errCode],
utils.safeunicode(logout_resp.get_text_info()[0] or "")
)
logger.error( _err_msg)
defer.returnValue("disconnect done!")
except Exception as err:
defer.returnValue(err)
开发者ID:gvsurenderreddy,项目名称:toughwlan,代码行数:34,代码来源:logout.py
示例3: event_toughcloud_mail_account_open
def event_toughcloud_mail_account_open(self, userinfo):
""" toughCloud mail api open notify without password event """
if not userinfo:
return
if not userinfo.get('email'):
logger.error('user email is None exit')
return
try:
api_secret = self.get_param_value("toughcloud_license")
service_mail = self.get_param_value("toughcloud_service_mail")
if not service_mail:
return
api_token = yield tools.get_sys_token()
params = dict(
token=api_token.strip(),
action='email',
mailto=userinfo.get('email'),
tplname=self.MAIL_TPLNAME,
customer=utils.safestr(userinfo.get('realname')),
username=userinfo.get('account_number'),
product=utils.safestr(userinfo.get('product_name')),
expire=userinfo.get('expire_date'),
service_call=self.get_param_value("toughcloud_service_call", ''),
service_mail=service_mail,
nonce=str(int(time.time()))
)
params['sign'] = apiutils.make_sign(api_secret.strip(), params.values())
resp = yield httpclient.fetch(self.MAIL_APIURL, postdata=urlencode(params))
logger.info(resp.body)
logger.info('open account send email without password success')
except Exception as err:
logger.exception(err)
开发者ID:YMXZ,项目名称:ToughRADIUS,代码行数:34,代码来源:account_open_notify.py
示例4: onSendError
def onSendError(self,err, disconnect_req):
if disconnect_req and self.db.query(models.TrOnline).filter_by(
nas_addr=disconnect_req.nas_addr,
acct_session_id=disconnect_req.acct_session_id).count() > 0:
radius_acct_stop.RadiusAcctStop(
self.dbengine,self.mcache,self.aes, disconnect_req).acctounting()
logger.error(u"send disconnect done! %s" % err.getErrorMessage())
开发者ID:WyattShao,项目名称:ToughRADIUS,代码行数:7,代码来源:radius_events.py
示例5: process
def process(self):
conn = self.db()
try:
nas_list = conn.query(models.TrwBas)
for nas in nas_list:
if not nas.dns_name:
continue
results, _, _ = yield client.lookupAddress(nas.dns_name)
if not results:
logger.error("domain {0} resolver empty".format(nas.dns_name))
if results[0].type == dns.A:
ipaddr = ".".join(str(i) for i in struct.unpack("BBBB", results[0].payload.address))
if ipaddr:
nas.ip_addr = ipaddr
conn.commit()
logger.info("domain {0} resolver {1} success".format(nas.dns_name,ipaddr))
else:
logger.info("domain {0} no ip address,{1}".format(nas.dns_name, repr(results)))
except Exception as err:
logger.error('ddns process error %s' % utils.safeunicode(err.message))
finally:
conn.close()
reactor.callLater(60, self.process, )
开发者ID:gvsurenderreddy,项目名称:toughwlan,代码行数:26,代码来源:ddns_task.py
示例6: process
def process(self, *args, **kwargs):
next_interval = self.get_notify_interval()
user_total = 0
online_total = 0
with make_db(self.db) as db:
try:
user_total = db.query(models.TrAccount).count()
online_total = db.query(models.TrOnline).count()
except Exception as err:
pass
try:
api_url = "https://www.toughcloud.net/api/v1/ping"
api_token = yield tools.get_sys_token()
params = dict(
token=api_token,
app="toughradius",
ver=__version__,
release=self.config.system.get('release',"standard"),
unum=user_total,
onum=online_total,
dist=' '.join(pf.linux_distribution()),
)
param_str = urlencode(params)
resp = yield httpclient.fetch(api_url+"?"+param_str,followRedirect=True)
logger.info("toughcloud ping resp code: %s"%resp.code)
except Exception as err:
logger.error(err)
defer.returnValue(next_interval)
开发者ID:YMXZ,项目名称:ToughRADIUS,代码行数:28,代码来源:cloudping.py
示例7: process
def process(self, *args, **kwargs):
self.logtimes()
next_interval = self.get_notify_interval()
backup_path = self.config.database.backup_path
backup_file = "trdb_cron_backup_%s.json.gz" % utils.gen_backep_id()
try:
self.db_backup.dumpdb(os.path.join(backup_path, backup_file))
logger.info(u"数据备份完成,下次执行还需等待 %s"%(self.format_time(next_interval)) )
except Exception as err:
logger.error(u"数据备份失败,%s, 下次执行还需等待 %s"%( repr(err), self.format_time(next_interval)) )
logger.exception(err)
try:
bak_list = [ bd for bd in os.listdir(backup_path) if 'trdb_cron_backup' in bd]
if len(bak_list) > 7:
logger.info("find expire backup file and remove")
_count = 0
for fname in bak_list:
fpath = os.path.join(backup_path, fname)
if (time.time() - os.path.getctime(fpath)) > 14:
os.remove(fpath)
_count += 1
logger.info("remove expire backup file %s"%fpath)
logger.info("remove expire backup file total %s"%_count)
except Exception as err:
logger.exception(err)
return next_interval
开发者ID:myapple,项目名称:ToughRADIUS,代码行数:28,代码来源:backup_data.py
示例8: processAcct
def processAcct(self, datagram, host, port):
try:
bas = self.find_nas(host)
if not bas:
raise PacketError('[Radiusd] :: Dropping packet from unknown host %s' % host)
secret, vendor_id = bas['bas_secret'], bas['vendor_id']
req = self.createAcctPacket(packet=datagram,
dict=self.dict, secret=six.b(str(secret)),vendor_id=vendor_id)
logger.info("[Radiusd] :: Received radius request: %s" % (repr(req)))
if self.config.system.debug:
logger.debug(req.format_str())
if req.code != packet.AccountingRequest:
raise PacketError('non-AccountingRequest packet on authentication socket')
if not req.VerifyAcctRequest():
raise PacketError('VerifyAcctRequest error')
reply = req.CreateReply()
status_type = req.get_acct_status_type()
if status_type in self.acct_class:
acct_func = self.acct_class[status_type](self,req.get_ticket()).acctounting
reactor.callLater(0.1,acct_func)
return reply
except Exception as err:
errstr = 'RadiusError:Dropping invalid acct packet from {0} {1},{2}'.format(
host, port, utils.safeunicode(err))
logger.error(errstr)
import traceback
traceback.print_exc()
开发者ID:niebaopeng,项目名称:ToughRADIUS,代码行数:32,代码来源:radiusd.py
示例9: process
def process(self, *args, **kwargs):
with make_db(self.db) as db:
try:
nodes = db.query(models.TrNode)
for node in nodes:
online_count = (
db.query(models.TrOnline.id)
.filter(
models.TrOnline.account_number == models.TrAccount.account_number,
models.TrAccount.customer_id == models.TrCustomer.customer_id,
models.TrCustomer.node_id == node.id,
)
.count()
)
stat = models.TrOnlineStat()
stat.node_id = node.id
stat.stat_time = int(time.time())
stat.total = online_count
db.add(stat)
db.commit()
logger.info("online stat task done")
except Exception as err:
db.rollback()
logger.error("online_stat_job err,%s" % (str(err)))
return 120.0
开发者ID:lxyjyy,项目名称:ToughRADIUS,代码行数:26,代码来源:online_stat.py
示例10: process
def process(self, *args, **kwargs):
self.logtimes()
with make_db(self.db) as db:
try:
nodes = db.query(models.TrNode)
for node in nodes:
r = db.query(
func.sum(models.TrOnline.input_total).label("input_total"),
func.sum(models.TrOnline.output_total).label("output_total")
).filter(
models.TrOnline.account_number == models.TrAccount.account_number,
models.TrAccount.customer_id == models.TrCustomer.customer_id,
models.TrCustomer.node_id == node.id
).first()
if r and all([r.input_total,r.output_total]):
stat = models.TrFlowStat()
stat.node_id = node.id
stat.stat_time = int(time.time())
stat.input_total = r.input_total
stat.output_total = r.output_total
db.add(stat)
# clean expire data
_time = int(time.time()) - (86400 * 2)
db.query(models.TrFlowStat).filter(models.TrFlowStat.stat_time < _time).delete()
db.commit()
logger.info("flow stat task done")
except Exception as err:
db.rollback()
logger.error('flow_stat_job err,%s'%(str(err)))
return self.get_notify_interval()
开发者ID:myapple,项目名称:ToughRADIUS,代码行数:33,代码来源:flow_stat.py
示例11: event_toughcloud_sms_account_open
def event_toughcloud_sms_account_open(self, userinfo):
""" toughCloud sms api open notify event """
if not userinfo:
return
if not userinfo.get('phone'):
logger.error('user phone is None exit')
return
api_secret = self.get_param_value("toughcloud_license")
api_token = yield tools.get_sys_token()
params = dict(
token=api_token.strip(),
action='sms',
tplname=self.SMS_TPLNAME,
phone=userinfo.get('phone'),
customer=utils.safestr(userinfo.get('realname')),
username=userinfo.get('account_number'),
product=utils.safestr(userinfo.get('product_name')),
password=userinfo.get('password'),
expire=userinfo.get('expire_date'),
nonce=str(int(time.time()))
)
params['sign'] = apiutils.make_sign(api_secret.strip(), params.values())
try:
resp = yield httpclient.fetch(self.SMS_APIURL, postdata=urlencode(params))
logger.info(resp.body)
logger.info('open account send short message success')
except Exception as err:
logger.exception(err)
开发者ID:YMXZ,项目名称:ToughRADIUS,代码行数:30,代码来源:account_open_notify.py
示例12: parse_form_request
def parse_form_request(self):
try:
print self.get_params()
return apiutils.parse_form_request(self.settings.config.system.secret, self.get_params())
except Exception as err:
logger.error(u"api authorize parse error, %s" % utils.safeunicode(traceback.format_exc()))
raise ValueError(u"Error: %s" % utils.safeunicode(err.message))
开发者ID:WyattShao,项目名称:ToughRADIUS,代码行数:7,代码来源:apibase.py
示例13: process
def process(self, *args, **kwargs):
try:
self.statdata.run_stat()
if self.cache.get(radius_statcache_key):
self.cache.update(radius_statcache_key,self.statdata)
else:
self.cache.set(radius_statcache_key,self.statdata)
except Exception as err:
logger.error('radius stat process error %s' % utils.safeunicode(err.message))
return 10.0
开发者ID:Evan-hu,项目名称:ToughRADIUS,代码行数:11,代码来源:radius_stat.py
示例14: init_route_permit
def init_route_permit(self):
with make_db(self.db) as conn:
try:
oprs = conn.query(models.TrOperator)
for opr in oprs:
if opr.operator_type > 0:
for rule in self.db.query(models.TrOperatorRule).filter_by(operator_name=opr.operator_name):
permit.bind_opr(rule.operator_name, rule.rule_path)
elif opr.operator_type == 0: # 超级管理员授权所有
permit.bind_super(opr.operator_name)
except Exception as err:
logger.error("init route error , %s" % str(err))
开发者ID:Evan-hu,项目名称:ToughRADIUS,代码行数:12,代码来源:httpd.py
示例15: process
def process(self, *args, **kwargs):
next_interval = self.get_notify_interval()
try:
api_url = "https://www.toughcloud.net/api/v1/ping"
api_token = yield tools.get_sys_token()
param_str = urlencode({'token':api_token})
resp = yield httpclient.fetch(api_url+"?"+param_str,followRedirect=True)
logger.info("toughcloud ping resp code: %s"%resp.code)
if resp.code == 200:
self.cache.set(toughcloud_ping_key,resp.body,expire=3600)
except Exception as err:
logger.error(err)
defer.returnValue(next_interval)
开发者ID:dhh123,项目名称:ToughRADIUS,代码行数:13,代码来源:cloudping.py
示例16: billing
def billing(self, online):
product = self.get_product_by_id(self.account.product_id)
if not product:
logger.error('product <%s> not exists' % self.account.product_id)
return
if product.product_policy not in (PPTimes,BOTimes,PPFlow,BOFlows):
self.update_online(self.request.nas_addr,
self.request.acct_session_id,
billing_times=self.request.acct_session_time,
input_total=self.get_input_total(),
output_total=self.get_output_total())
else:
self.bill_funcs[product.product_policy](online, product)
开发者ID:WyattShao,项目名称:ToughRADIUS,代码行数:14,代码来源:radius_billing.py
示例17: get_error_html
def get_error_html(self, status_code=500, **kwargs):
logger.error("http error : [status_code:{0}], {1}".format(status_code, utils.safestr(kwargs)))
if self.settings.debug:
traceback.print_exc()
if self.request.headers.get('X-Requested-With') == 'XMLHttpRequest':
return self.render_json(code=1, msg=u"%s:服务器处理失败,请联系管理员" % status_code)
if status_code == 404:
return self.render_error(msg=u"404:页面不存在")
elif status_code == 403:
return self.render_error(msg=u"403:非法的请求")
elif status_code == 500:
return self.render_error(msg=u"500:服务器处理失败,请联系管理员")
else:
return self.render_error(msg=u"%s:服务器处理失败,请联系管理员" % status_code)
开发者ID:lxyjyy,项目名称:ToughRADIUS,代码行数:15,代码来源:base.py
示例18: check_sign
def check_sign(api_secret, msg):
"""
>>> check_sign("123456",dict(code=1,s='2',msg=u'中文',sign='33C9065427EECA3490C5642C99165145'))
True
"""
if "sign" not in msg:
return False
sign = msg['sign']
params = [utils.safestr(msg[k]) for k in msg if k != 'sign']
local_sign = make_sign(api_secret, params)
result = (sign == local_sign)
if not result:
logger.error("check_sign failure, sign:%s != local_sign:%s" %(sign,local_sign))
return result
开发者ID:lichaoye,项目名称:toughlib,代码行数:15,代码来源:apiutils.py
示例19: acctounting
def acctounting(self):
if not self.account:
return logger.error(
"[Acct] Received an accounting update request but user[%s] not exists"% self.request.account_number)
ticket = Storage(**self.request)
_datetime = datetime.datetime.now()
online = self.get_online(ticket.nas_addr,ticket.acct_session_id)
if not online:
session_time = ticket.acct_session_time
stop_time = _datetime.strftime( "%Y-%m-%d %H:%M:%S")
start_time = (_datetime - datetime.timedelta(seconds=int(session_time))).strftime( "%Y-%m-%d %H:%M:%S")
ticket.acct_start_time = start_time
ticket.acct_stop_time = stop_time
ticket.start_source= STATUS_TYPE_STOP
ticket.stop_source = STATUS_TYPE_STOP
self.add_ticket(ticket)
else:
self.del_online(ticket.nas_addr,ticket.acct_session_id)
ticket.acct_start_time = online.acct_start_time
ticket.acct_stop_time= _datetime.strftime( "%Y-%m-%d %H:%M:%S")
ticket.start_source = online.start_source
ticket.stop_source = STATUS_TYPE_STOP
self.add_ticket(ticket)
self.billing(online)
logger.info('%s Accounting stop request, remove online'% self.account.account_number)
开发者ID:gyc291195485,项目名称:ToughRADIUS,代码行数:27,代码来源:radius_acct_stop.py
示例20: acctounting
def acctounting(self):
if not self.account:
dispatch.pub(UNLOCK_ONLINE_EVENT,
self.request.account_number,self.request.nas_addr, self.request.acct_session_id,async=True)
return logger.error(
"[Acct] Received an accounting update request but user[%s] not exists"% self.request.account_number)
ticket = Storage(**self.request)
online = self.get_online(ticket.nas_addr,ticket.acct_session_id)
if not online:
sessiontime = ticket.acct_session_time
updatetime = datetime.datetime.now()
_starttime = updatetime - datetime.timedelta(seconds=sessiontime)
online = Storage(
account_number = self.account.account_number,
nas_addr = ticket.nas_addr,
acct_session_id = ticket.acct_session_id,
acct_start_time = _starttime.strftime( "%Y-%m-%d %H:%M:%S"),
framed_ipaddr = ticket.framed_ipaddr,
mac_addr = ticket.mac_addr or '',
nas_port_id = ticket.nas_port_id or '',
billing_times = ticket.acct_session_time,
input_total = self.get_input_total(),
output_total = self.get_output_total(),
start_source = STATUS_TYPE_UPDATE
)
self.add_online(online)
self.billing(online)
logger.info('%s Accounting update request, update online'% self.account.account_number)
开发者ID:WyattShao,项目名称:ToughRADIUS,代码行数:30,代码来源:radius_acct_update.py
注:本文中的toughlib.logger.error函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论