Skip to main content

Python gRPC 回调方式实现CS通讯

Project description

syslog_parse

Documentation

The documentation is hosted at https://github.com/BingerYang/grpc_route

Installation

syslog_parse requires Python **Python 3.x >= 3.4.

Install from PyPI::

$ pip install grpc_route

Usage

  1. 单条解析

>>> from syslog_parse import parse
>>> a = "<189>Jan 20 2019 06:31:16.173 US-LAX-2-CR-2-new %%01OPS/5/OPS_LOGIN(s):CID=0x80b40445;Succeeded in establishing the OPS connection.(ServiceType=embedding-script, UserName=_soc_l3loop.py, Ip=0.0.0.0, VpnName=_public_)"
>>> parse(a)
<generator object Parser.cycle_parse at 0x10342cb10>
>>> parse(a)
Message(facility=<Facility.local7: 23>, severity=<Severity.notice: 5>, timestamp=datetime.datetime(2019, 1, 20, 6, 31, 16), hostname='US-LAX-2-CR-2-new', module='OPS', digest='OPS_LOGIN', content='CID=0x80b40445;Succeeded in establishing the OPS connection.(ServiceType=embedding-script, UserName=_soc_l3loop.py, Ip=0.0.0.0, VpnName=_public_)')
  1. 循环解析

>>> from syslog_parse import cycle_parse
>>> aa = "<189>Jan 20 2019 06:31:17.60.1 US-DFW-1-CR-1 %%01INFO/5/SUPPRESS_LOG(l)[8480539]:Last message repeated 20 times.(InfoID=1079656494, ModuleName=VTY, InfoAlias=ACL_DENY)<7>Jan 20 14:30:56 AP-HKG-2-CR-1-RE0 kernel: rts_commit_proposalmput op: 2, peer_type:17, peer_index:3, vskid:0, seqno:14447884, flag:9,<7>Jan 20 14:30:56 AP-HKG-2-CR-1-RE0 kernel: rts_commit_proposalmput op: 2, peer_type:17, peer_index:1, vskid:0, seqno:14447884, flag:9,<7>Jan 20 14:30:56 AP-HKG-2-CR-1-RE0 kernel: rts_commit_proposalmput op: 2, peer_type:17, peer_index:5, vskid:0, seqno:14447884, flag:9,<37>Jan 20 14:30:56 AP-HKG-2-CR-1-RE0 snmpd[15576]: SNMPD_AUTH_RESTRICTED_ADDRESS: nsa_initial_callback: request from address 103.36.133.244 not allowed<7>Jan 20 14:30:57 AP-HKG-2-CR-1-RE0 kernel: rts_commit_proposalmput op: 2, peer_type:17, peer_index:3, vskid:0, seqno:14447886, flag:9,<7>Jan 20 06:25:22 AP-SGN-1-CR-1-RE0 kernel: rts_commit_proposalmput op: 2, peer_type:17, peer_index:1, vskid:0, seqno:1158657, flag:9,<7>Jan 20 14:30:57 AP-HKG-2-CR-1-RE0 kernel: rts_commit_proposalmput op: 2, peer_type:17, peer_index:5, vskid:0, seqno:14447886, flag:9,<7>Jan 20 14:30:57 AP-HKG-2-CR-1-RE0 kernel: rts_commit_proposalmput op: 2, peer_type:17, peer_index:1, vskid:0, seqno:14447886, flag:9,<188>Jan 20 2019 06:31:14.967 SA-SAO-2-CR-1 %%01SOC/4/hwBaseArpVlanCarEnhanceTrap_clear(l):VS=Admin-VS-CID=0x80c4046e-alarmID=0x09e62006-clearType=service_resume;ARP VLAN CAR became ineffective on an interface.(Logical Interface = Eth-Trunk4, Physical Interface = GigabitEthernet3/0/6, Pe-Vlan = 0, Ce-Vlan = 0, Sample Rate = 499)"
>>> cycle_parse(aa)
<generator object Parser.cycle_parse at 0x10342cb10>
>>> next(cycle_parse(aa))
Message(facility=<Facility.local7: 23>, severity=<Severity.notice: 5>, timestamp=datetime.datetime(2019, 1, 20, 6, 31, 17), hostname='US-DFW-1-CR-1', module='INFO', digest='SUPPRESS_LOG', content='Last message repeated 20 times.(InfoID=1079656494, ModuleName=VTY, InfoAlias=ACL_DENY)')
>>> for msg in cycle_parse(bb):
    print(msg)
Message(facility=<Facility.local7: 23>, severity=<Severity.notice: 5>, timestamp=datetime.datetime(2019, 1, 20, 6, 31, 17), hostname='US-DFW-1-CR-1', module='INFO', digest='SUPPRESS_LOG', content='Last message repeated 20 times.(InfoID=1079656494, ModuleName=VTY, InfoAlias=ACL_DENY)')
Message(facility=<Facility.kernel: 0>, severity=<Severity.debug: 7>, timestamp=datetime.datetime(2019, 1, 20, 14, 30, 56), hostname='AP-HKG-2-CR-1-RE0', module='kernel', digest='rts_commit_proposalmput op', content='2, peer_type:17, peer_index:3, vskid:0, seqno:14447884, flag:9,')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grpc_route-0.1.0.19123118.tar.gz (6.6 kB view details)

Uploaded Source

File details

Details for the file grpc_route-0.1.0.19123118.tar.gz.

File metadata

  • Download URL: grpc_route-0.1.0.19123118.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.7.4

File hashes

Hashes for grpc_route-0.1.0.19123118.tar.gz
Algorithm Hash digest
SHA256 f0117515481ef8a0e0b8238e71df4e7a5c02fe2ff4df3acc1dfb6b09bb1e5c92
MD5 dbdc813700567dcda89f17a357a42908
BLAKE2b-256 2e2b0a6a68c650c3e0d83fd565bbc2c63b3b5e706e42cbab8c2ad0134bfa420b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page