update
This commit is contained in:
BIN
hik_push/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
hik_push/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
hik_push/__pycache__/read_event.cpython-311.pyc
Normal file
BIN
hik_push/__pycache__/read_event.cpython-311.pyc
Normal file
Binary file not shown.
BIN
hik_push/mapping/__pycache__/__init__.cpython-311.pyc
Normal file
BIN
hik_push/mapping/__pycache__/__init__.cpython-311.pyc
Normal file
Binary file not shown.
BIN
hik_push/mapping/__pycache__/event_map.cpython-311.pyc
Normal file
BIN
hik_push/mapping/__pycache__/event_map.cpython-311.pyc
Normal file
Binary file not shown.
1
hik_push/rea.json
Normal file
1
hik_push/rea.json
Normal file
@ -0,0 +1 @@
|
||||
{'data': {'channelID': 1, 'channelName': 'B区西~油库', 'dataProcInterval': '24', 'dataType': 'behavioralAnalysis', 'dateTime': '2024-02-01T11:23:54.000+08:00', 'eventDescription': 'fielddetection', 'eventType': 'fielddetection', 'ipAddress': '192.168.1.11', 'picUploadInterval': '20', 'portNo': 8000, 'recvTime': '2024-02-01T11:23:57.711+08:00', 'sendTime': '2024-02-01T11:23:57.735+08:00', 'userIds': ['fsdf34324', 'dsffee879'], '_detectionResult': [{'detectionTarget': 1, 'duration': 1, 'imageUrl': 'http://192.168.1.250:6120/pic?0d44=de54ida-=o6018p66ea906d-63599cbbb*562s=**113==tp*7417=6807757*3861=6l9*0814=fo916-12*le1-od2620224252', 'rate': 0, 'rectType': 'others', 'regionCoordinatesList': [{'positionX': 0, 'positionY': 0.5210000276565552}, {'positionX': 0.9929999709129332, 'positionY': 0.8059999942779541}, {'positionX': 0.9929999709129332, 'positionY': 0.02500000037252903}, {'positionX': 0.006000000052154064, 'positionY': 0}], 'sensitivityLevel': 4, 'targetAttrs': {'cameraIndexCode': 'c08f3b8317a743069ac18fc1f9d3dfc3', 'deviceIndexCode': '9c6ed401392e454984c8002bdd96c255', 'imageServerCode': '53a3b8cb-b3e6-45ff-ae95-65ab3a157551', 'picServerIndexCode': '53a3b8cb-b3e6-45ff-ae95-65ab3a157551'}, 'targetRect': {'height': 0.4860000014305115, 'positionX': 0.02400000020861626, 'positionY': 0.4329999983310699, 'width': 0.09200000017881392}, 'taskInfo': {'ruleCustomName': '规则1', 'ruleID': 0, 'ruleName': '规则1'}}]}, 'eventId': '00091540-B916-8546-8C42-8582BD2F66F3', 'eventType': '区域入侵', 'happenTime': '2024-02-01T11:23:54.000+08:00', 'srcIndex': 'c08f3b8317a743069ac18fc1f9d3dfc3', 'srcName': 'B区西~油库', 'srcParentIndex': '9c6ed401392e454984c8002bdd96c255', 'srcType': 'camera', 'status': 0, 'timeout': 0}
|
@ -1,61 +1,71 @@
|
||||
import asyncio
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import logging
|
||||
import yaml
|
||||
|
||||
from hik_push.mapping.event_map import event_map
|
||||
import requests
|
||||
from redis import asyncio as aioredis
|
||||
|
||||
|
||||
async def read_event():
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
# 读取配置文件
|
||||
home_dir = Path.home()
|
||||
with open(home_dir / '.config' / 'hik-push' / 'config.yaml', 'r', encoding='utf-8') as f:
|
||||
config = yaml.safe_load(f)
|
||||
if "user_ids" not in config:
|
||||
print("请配置user_ids")
|
||||
logging.error("请配置user_ids")
|
||||
return
|
||||
if "devices" not in config:
|
||||
print("请配置devices")
|
||||
# if "devices" not in config:
|
||||
# logging.error("请配置devices")
|
||||
# return
|
||||
if "event_type" not in config:
|
||||
logging.error("请配置event_type")
|
||||
return
|
||||
print(config)
|
||||
if "push_url" not in config:
|
||||
logging.error("请配置push_url")
|
||||
return
|
||||
|
||||
logging.info(config)
|
||||
user_map = config['user_ids']
|
||||
device_map = config['devices']
|
||||
event_map = config['event_type']
|
||||
push_url = config['push_url']
|
||||
redis_client = await aioredis.Redis(host="127.0.0.1", port=7019, password="SMHdFrlK")
|
||||
while True:
|
||||
data = await redis_client.brpop("hik-sub-event")
|
||||
sub_json = json.loads(data[1].decode('utf-8'))
|
||||
try:
|
||||
data = await redis_client.brpop("hik-sub-event")
|
||||
sub_json = json.loads(data[1].decode('utf-8'))
|
||||
events = sub_json["params"]["events"]
|
||||
for event in events:
|
||||
# 将eventType ID 替换为中文字符串
|
||||
event_type = event['eventType']
|
||||
logging.info(event_type)
|
||||
event_type_str = event_map.get(event_type, "未知事件类型")
|
||||
event['eventType'] = event_type_str
|
||||
#
|
||||
src_index = event["srcIndex"]
|
||||
device_name = device_map.get(src_index, "未知设备")
|
||||
user_ids = user_map.get(device_name, [])
|
||||
event['deviceName'] = device_name
|
||||
event['userIds'] = user_ids
|
||||
if "data" in event:
|
||||
# 如果存在 data 属性
|
||||
# ip_address
|
||||
ip_address = event["data"]["ipAddress"]
|
||||
|
||||
# 根据 ip_address 获取对应设备名称
|
||||
device_name = device_map.get(ip_address, "未知设备")
|
||||
event['data']['deviceName'] = device_name
|
||||
|
||||
# 根据 ip_address 获取对应 userid 数组
|
||||
user_ids = user_map.get(ip_address, [])
|
||||
event['data']['userIds'] = user_ids
|
||||
# 替换分析结果字段
|
||||
if "eventType" in event['data']:
|
||||
detection_field_name = event['data']['eventType']
|
||||
if detection_field_name in event['data']:
|
||||
event['data']["_detectionResult"] = event['data'].pop(detection_field_name)
|
||||
# TODO: 请求推送 api
|
||||
#
|
||||
print(event)
|
||||
# 请求推送 api
|
||||
logging.info(event)
|
||||
try:
|
||||
push_resp = requests.post(push_url, json=event).content.decode('utf-8')
|
||||
logging.info(push_resp)
|
||||
except Exception as e:
|
||||
logging.error(f"网络错误推送失败: {e}")
|
||||
|
||||
except Exception as e:
|
||||
print("error: ", e)
|
||||
logging.error("error: ", e)
|
||||
continue
|
||||
finally:
|
||||
await asyncio.sleep(0.5)
|
||||
|
42
hik_push/sub_body.json
Normal file
42
hik_push/sub_body.json
Normal file
@ -0,0 +1,42 @@
|
||||
{
|
||||
"eventTypes": [
|
||||
131588,
|
||||
131585,
|
||||
131586,
|
||||
131587,
|
||||
131590,
|
||||
131593,
|
||||
131592,
|
||||
131591,
|
||||
131594,
|
||||
131595,
|
||||
131664,
|
||||
131665,
|
||||
131596,
|
||||
131603,
|
||||
131605,
|
||||
131597,
|
||||
131666,
|
||||
131609,
|
||||
131598,
|
||||
131599,
|
||||
131600,
|
||||
131601,
|
||||
131602,
|
||||
131604,
|
||||
131606,
|
||||
131607,
|
||||
131611,
|
||||
192518,
|
||||
192517,
|
||||
192516,
|
||||
192515,
|
||||
192514,
|
||||
192513,
|
||||
930335,
|
||||
20210724,
|
||||
20210724
|
||||
],
|
||||
"eventDest": "http://127.0.0.1:8000/eventRcv",
|
||||
"subType": 0
|
||||
}
|
Reference in New Issue
Block a user