def __init__(self, uri, timeout=10):
     uri = uri.replace('/','').split(':')
     assert(len(uri) == 3)
     assert(uri[0] == 'udp')
     self._server_address = (uri[1], int(uri[2]))
     self.clock = zkem()
     self.timeout=timeout
示例#2
0
 def connect_device(self):
     host = self.host
     port = self.port
     device = zkemapi.zkem()
     connect = device.connect(host=host, port=port)
     if connect:
         raise except_orm(_('Success!'),
                          _('Connection completed successfully'))
     else:
         raise except_orm(_('Connection Failed!'),
                          _('Please review parameters'))
示例#3
0
 def get_attendace_log(self, cr, uid):
     attendance = self.pool['hr.attendance']
     employee = self.pool['hr.employee']
     devices_ids = self.search(cr, uid, [])
     for zk_device in self.browse(cr, uid, devices_ids, context=None):
         host = zk_device.host
         port = zk_device.port
         timezone = -zk_device.timezone
         device = zkemapi.zkem()
         connect = device.connect(host=host, port=port)
         connect
         attendance_log = device.unpack_attendance_log()
         attendance_log
         for log in attendance_log:
             employee_id = employee.search(cr, uid,
                                           [('zk_id', '=', log[0])])
             if not employee_id:
                 raise except_orm(
                     _('Error!'),
                     _('There is no employee with ID %s') % log[0])
             date = log[1] + timedelta(hours=timezone)
             attendance_ids = attendance.search(
                 cr, uid, [('employee_id', '=', employee_id[0])])
             last_id = attendance_ids and max(attendance_ids)
             attendance_obj = attendance.browse(cr,
                                                uid,
                                                last_id,
                                                context=None)
             if not attendance_obj:
                 sign = 'sign_in'
             elif attendance_obj[0].action == 'sign_in':
                 sign = 'sign_out'
             else:
                 sign = 'sign_in'
             attendance.create(
                 cr, uid, {
                     'employee_id': employee_id[0],
                     'name': datetime.strftime(date, dt),
                     'action': sign,
                 })
         device.clear_attendance_log()
from  zkemapi import zkem
import pprint
from config import FICHERO_CFG
from config import DB_CFG
from config import DESCARGA
from config import PRO_ROOT
from config import F_PURGADO_PREFIX
import datetime
import getopt
import pgdb
from exceptions import StandardError
import sys

fichero=zkem()

if len(DESCARGA) < 1:
  print "No se han definido ficheros para la descarga"
  print "Revisar la configuracion del conjunto DESCARGA"
  sys.exit(0)

print "Conectandose a la base de datos"
try:
  cx = pgdb.connect( host = DB_CFG['host']+':'+DB_CFG['port'], user=DB_CFG['user'], password=DB_CFG['pass'], database=DB_CFG['db'] )
except StandardError as e:
  print "Error: %s" % (e.message)
  sys.exit(1)

# me fijo si esta el parametro para purgar los ficheros
purgar = False;
parametros, extra_args = getopt.getopt(sys.argv[1:],'p')
for (parametro,valor) in parametros:
示例#5
0
    not crit_offset or crit_offset <= 0 or \
    not host):
    print "Use: -h host | ip addr -w warn_offset (sec) -c crit_offset (sec)"
    sys.exit(UNKNOWN)

if (not warn_offset.isdigit() or not crit_offset.isdigit()):
    print "ERROR: wrong limits for -w or -c"
    sys.exit(UNKNOWN)

crit_offset, warn_offset = (int(crit_offset), int(warn_offset))
if (crit_offset < warn_offset):
    aux = crit_offset
    crit_offset = warn_offset
    warn_offset = aux

ac_dev = zkem()
status_cx = ac_dev.connect(host=host, debug=False, timeout=7)
if status_cx:
    ts = ac_dev.get_time()
    ac_dev.disconnect()
    ts = datetime.datetime.strptime(ts, '%Y-%m-%d %H:%M:%S')
    ts_str = ts.strftime('%Y-%m-%d %H:%M:%S')
    delta = delta_seconds(ts)
    # delta puede ser negativo si la fecha de referencia esta en
    # el pasado con respecto a la chequeada, por eso uso valor
    # absoluto
    delta_abs = int(math.fabs(delta))

    if (delta_abs > crit_offset):
        print "CRITICAL: ts_fichador=" + ts_str + " delta=" + str(
            delta) + "  warn=" + str(warn_offset) + "  crit=" + str(