record_log.py 568 B

123456789101112131415161718192021
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter service
  5. name:record_log.py 记录网关日志
  6. author:rabin
  7. key:log/hw/gateway/gateway
  8. """
  9. from demeter.core import *
  10. class Record_log(object):
  11. def handle(self, record, config, value):
  12. model = Demeter.model('device_gateway')
  13. model.hardware_id = config['parent']
  14. data = model.select(type='fetchone')
  15. if data:
  16. logModel = Demeter.model('log')
  17. logModel.farm_id = data['farm_id']
  18. logModel.gateway_id = data['id']
  19. logModel.content = value
  20. logModel.insert()