Skip to content

Commit 46266a6

Browse files
committed
chg: usr: Changed feed dir to /data/sitch/feed, and log dir to /data/sitch/log/. Relocated filebeat registry to /data/sitch/log/fb_registry
* Target specific radio types. Speed up feed ingestion for GSM-only sensors. * Added alarm 130 for detection of a bad Mobile Country Code (MCC). * Use human-friendly sensor name in metrics, derived from Resin device name. Location name override still works for non-Resin environments. * Length of sensor processing queues added to health check. * Alerts contain sensor ID, derived from Resin device name. * Geo distance check validates that lon/lat could be valid coordinates. * Fixed lat/lon swap bug in Utility.calculate_distance
1 parent b5ac687 commit 46266a6

8 files changed

Lines changed: 54 additions & 19 deletions

File tree

Dockerfile

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,13 @@ COPY configs/filebeat.json /etc/templates
4747
# Get the scripts in place
4848
COPY sitch/ /app/sitch
4949

50+
COPY requirements.txt /requirements.txt
51+
5052
WORKDIR /app/sitch
5153

5254
RUN pip install virtualenv==15.1.0 && \
5355
virtualenv venv && \
5456
. ./venv/bin/activate && \
55-
pip install \
56-
psutil==5.0.1 \
57-
pyserial==3.2.1 \
58-
pyyaml==3.12 \
59-
gps3==0.33.3 \
60-
hvac==0.2.16 \
61-
kalibrate==1.1.2 \
62-
haversine==0.4.5 \
63-
python-dateutil==2.6.0 \
64-
python-geoip==1.2 \
65-
python-geoip-geolite2==2015.303 \
66-
pyudev==0.21.0 \
67-
LatLon==1.0.2
57+
pip install -r /requirements.txt
6858

6959
CMD /app/sitch/venv/bin/python ./runner.py 2>&1

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ We expect the following environment variables to be set in Resin:
6161
| FEED_RADIO_TARGETS | List of radios for feed (optional, defaults to GSM) |
6262

6363

64-
6564
The CGI_WHITELIST will suppress alert 110 (BTS metadata changed) if the CGI of
6665
channel 0 in your GSM modem output matches an item in CGI_WHITELIST. This is
6766
the format you should use: `MCC:MNC:LAC:CELLID,MCC:MNC:LAC:CELLID` This is

requirements.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
psutil==5.0.1
2+
pyserial==3.2.1
3+
pyyaml==3.12
4+
gps3==0.33.3
5+
hvac==0.2.16
6+
kalibrate==1.1.2
7+
haversine==0.4.5
8+
python-dateutil==2.6.0
9+
python-geoip==1.2
10+
python-geoip-geolite2==2015.303
11+
pyudev==0.21.0
12+
LatLon==1.0.2

sitch/sitchlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
from geo_correlator import GeoCorrelator # NOQA
1515

1616
__author__ = "Ash Wilson"
17-
__version__ = "3.7.0"
17+
__version__ = "3.7.1"

sitch/sitchlib/cgi_correlator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ def build_chan_here(cls, channel, state):
160160
try:
161161
chan["lat"] = channel["feed_info"]["lat"]
162162
chan["lon"] = channel["feed_info"]["lon"]
163-
here["lat"] = state["geometry"]["coordinates"][0]
164-
here["lon"] = state["geometry"]["coordinates"][1]
163+
here["lat"] = state["geometry"]["coordinates"][1]
164+
here["lon"] = state["geometry"]["coordinates"][0]
165165
except (TypeError, ValueError, KeyError) as e:
166166
print("CgiCorrelator: Incomplete geo info...")
167167
print("CgiCorrelator: Error: %s" % str(e))

sitch/sitchlib/location_tool.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ def get_geo_for_ip(cls, ip_address):
2626
print(msg)
2727
return None
2828

29+
@classmethod
30+
def validate_geo(cls, latlon):
31+
"""Validate that lon/lat are valid numbers for Planet Earth"""
32+
lat = float(latlon[0])
33+
lon = float(latlon[1])
34+
valid = True
35+
if lat < -90:
36+
valid = False
37+
elif lat > 90:
38+
valid = False
39+
elif lon < -180:
40+
valid = False
41+
elif lon > 180:
42+
valid = False
43+
else:
44+
pass
45+
return valid
46+
2947
@classmethod
3048
def get_distance_between_points(cls, point_1, point_2):
3149
"""Calculate distance between points.
@@ -40,6 +58,12 @@ def get_distance_between_points(cls, point_1, point_2):
4058
if None in [point_1, point_2]:
4159
print("LocationTool: Invalid geo value. Returning 0 for distance.")
4260
distance = 0
61+
elif cls.validate_geo(point_1) is False:
62+
print("LocationTool: Invalid geo lat/lon value(%s). Distance = 0." % str(point_1)) # NOQA
63+
distance = 0
64+
elif cls.validate_geo(point_2) is False:
65+
print("LocationTool: Invalid geo lat/lon value(%s). Distance = 0." % str(point_2)) # NOQA
66+
distance = 0
4367
else:
4468
point_1 = (float(point_1[0]), float(point_1[1]))
4569
point_2 = (float(point_2[0]), float(point_2[1]))

sitch/sitchlib/utility.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ def calculate_distance(cls, lon_1, lat_1, lon_2, lat_2):
122122
if None in [lon_1, lat_1, lon_2, lat_2]:
123123
print("Utility: Geo coordinate is zero, not resolving distance.")
124124
return 0
125-
pos_1 = (lon_1, lat_1)
126-
pos_2 = (lon_2, lat_2)
125+
pos_1 = (lat_1, lon_1)
126+
pos_2 = (lat_2, lon_2)
127127
dist_in_km = LocationTool.get_distance_between_points(pos_1, pos_2)
128128
dist_in_m = dist_in_km * 1000
129129
return dist_in_m

sitch/tests/unit/test_unit_location_tool.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,13 @@ def test_get_distance_between_points_fail(self):
3232
chattanooga = (35.244, 85.1835)
3333
distance = loc_tool.get_distance_between_points(elseweyr, chattanooga)
3434
assert distance == 0
35+
36+
def test_geo_validator_pass(self):
37+
lon = -122.4095923
38+
lat = 37.782316
39+
assert sitchlib.LocationTool.validate_geo((lat, lon)) is True
40+
41+
def test_geo_validator_fail(self):
42+
lat = -122.4095923
43+
lon = 37.782316
44+
assert sitchlib.LocationTool.validate_geo((lat, lon)) is False

0 commit comments

Comments
 (0)