mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-04 12:48:00 +00:00
Option to paste data from test_ipv4_variable_time to influx database
Signed-off-by: lanforge <stidmatt@gmail.com>
This commit is contained in:
@@ -21,13 +21,8 @@ class RecordInflux(LFCliBase):
|
||||
_influx_user=None,
|
||||
_influx_passwd=None,
|
||||
_influx_db=None,
|
||||
_longevity=None,
|
||||
_monitor_interval=None,
|
||||
_target_kpi=None,
|
||||
_devices=None,
|
||||
_debug_on=False,
|
||||
_exit_on_fail=False
|
||||
):
|
||||
_exit_on_fail=False):
|
||||
super().__init__(_influx_host,
|
||||
_port,
|
||||
_debug=_debug_on,
|
||||
@@ -37,10 +32,6 @@ class RecordInflux(LFCliBase):
|
||||
self.influx_user = _influx_user
|
||||
self.influx_passwd = _influx_passwd
|
||||
self.influx_db = _influx_db
|
||||
self.longevity = _longevity
|
||||
self.stations = _devices
|
||||
self.monitor_interval = _monitor_interval
|
||||
self.target_kpi = _target_kpi
|
||||
|
||||
def posttoinflux(self,station,key,response,client):
|
||||
json_body = [
|
||||
@@ -58,26 +49,29 @@ class RecordInflux(LFCliBase):
|
||||
]
|
||||
client.write_points(json_body)
|
||||
|
||||
def getdata(self):
|
||||
def getdata(self,
|
||||
devices=None,
|
||||
target_kpi=None,
|
||||
longevity=None,
|
||||
monitor_interval=None):
|
||||
url = 'http://'+self.host+':8080/port/1/1/'
|
||||
client = InfluxDBClient(self.host,
|
||||
8086,
|
||||
self.influx_user,
|
||||
self.influx_passwd,
|
||||
self.influx_db)
|
||||
end = datetime.datetime.now() + datetime.timedelta(0, self.longevity)
|
||||
end = datetime.datetime.now() + datetime.timedelta(0, longevity)
|
||||
while datetime.datetime.now() < end:
|
||||
stations = self.stations
|
||||
for station in stations:
|
||||
for station in devices:
|
||||
url1 = url + station
|
||||
response = json.loads(requests.get(url1).text)
|
||||
if self.target_kpi is None:
|
||||
if target_kpi is None:
|
||||
for key in response['interface'].keys():
|
||||
self.posttoinflux(station, key, response, client)
|
||||
else:
|
||||
targets=self.target_kpi+['ip','ipv6 address','alias','mac']
|
||||
targets = target_kpi+['ip','ipv6 address','alias','mac']
|
||||
response['interface']={your_key: response['interface'][your_key] for your_key in targets}
|
||||
for key in response['interface'].keys():
|
||||
self.posttoinflux(station, key, response, client)
|
||||
|
||||
time.sleep(self.monitor_interval)
|
||||
time.sleep(monitor_interval)
|
||||
|
||||
Reference in New Issue
Block a user