Change in python/osmo-python-tests[master]: Update trap helper

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Max gerrit-no-reply at lists.osmocom.org
Tue Nov 27 17:02:27 UTC 2018


Max has uploaded this change for review. ( https://gerrit.osmocom.org/11951


Change subject: Update trap helper
......................................................................

Update trap helper

* add missing import
* update docs
* add helper functions

Change-Id: Ie6dc8808efc76ad96b400913e5caa405bce7d970
Related: SYS#4399
---
M osmopy/trap_helper.py
1 file changed, 40 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/python/osmo-python-tests refs/changes/51/11951/1

diff --git a/osmopy/trap_helper.py b/osmopy/trap_helper.py
index 4704564..f7a64c8 100644
--- a/osmopy/trap_helper.py
+++ b/osmopy/trap_helper.py
@@ -22,7 +22,7 @@
  */
 """
 
-import sys, os, signal, logging, logging.handlers
+import sys, os, datetime, signal, logging, logging.handlers
 from functools import partial
 from osmopy.twisted_ipa import CTRL
 from twisted.internet import defer
@@ -35,6 +35,42 @@
 # keys from OpenBSC openbsc/src/libbsc/bsc_vty.c
 fix = { 'invalid' : 0, 'fix2d' : 1, 'fix3d' : 1 } # SOAP server treats it as boolean but expects int
 
+def split_type(v):
+    """
+    Split TRAP type into list
+    """
+    (l, _) = v.split()
+    return l.split('.')
+
+def get_r(v):
+    """
+    Split TRAP record
+    """
+    (_, r) = v.split()
+    return r
+
+def get_type(v):
+    """
+    Get TRAP type
+    """
+    loc = split_type(v)
+    return loc[-1]
+
+def make_params(bsc, data):
+    """
+    Make parameters for request
+    """
+    (ts, fx, lat, lon, _, opr, adm, pol, _, _) = data.split(',')
+    tstamp = datetime.datetime.fromtimestamp(float(ts)).isoformat()
+    return {'bsc_id': bsc, 'lon': lon, 'lat': lat, 'position_validity': fix.get(fx, 0), 'time_stamp': tstamp, 'oper_status': oper.get(opr, 2), 'admin_status': admin.get(adm, 2), 'policy_status': policy.get(pol, 3) }
+
+def p_h(v):
+    """
+    Parse helper for method dispatch: expected format is net.0.bsc.666.bts.2.trx.1
+    """
+    loc = split_type(v)
+    return partial(lambda a, i: a[i] if len(a) > i else None, loc)
+
 class Trap(CTRL):
     """
     TRAP handler (agnostic to factory's client object)
@@ -109,6 +145,9 @@
     os.execl(path, script, *sys.argv[1:])
 
 def debug_init(name, is_debug, output):
+    """
+    Initialize signal handlers and logging
+    """
     log = logging.getLogger(name)
     if is_debug:
         log.setLevel(logging.DEBUG)

-- 
To view, visit https://gerrit.osmocom.org/11951
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: python/osmo-python-tests
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie6dc8808efc76ad96b400913e5caa405bce7d970
Gerrit-Change-Number: 11951
Gerrit-PatchSet: 1
Gerrit-Owner: Max <msuraev at sysmocom.de>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181127/4c69b979/attachment.htm>


More information about the gerrit-log mailing list