Skip to content

Commit

Permalink
Merge pull request #7 from northpowered/4-km-122-support
Browse files Browse the repository at this point in the history
Supporting of Potok KM-122
  • Loading branch information
northpowered authored Sep 5, 2022
2 parents 1e2cc74 + 5671f21 commit 02bb9e7
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FROM python:3.10-buster
WORKDIR /app

COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
RUN pip3 install --no-cache-dir -r requirements.txt

COPY . .

Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Supported devices:
- Juniper
- Eltex (ESR series)
- MT M716
- Potok KM-122

TODO:
- Extend devices support
Expand All @@ -41,6 +42,17 @@ optional arguments:
Logging path {stdout,FILE}
--version show programs version number and exit
```

## SLA statuses

| Status | Int value | Reccomended color | Description |
| ----------- | ----------- |------------------ |------------ |
| NoData | 0 | Black | No recieved data or parcing error |
| Normal | 1 | Green | Target is available and RTT less then policy |
| Warning | 2 | Yellow | Target is available and RTT bigger then policy |
| Error | 3 | Red | Target is unavailable |
| OutOfService| 4 | Green | Target is available and policy was not defined |

### Install:

```bash
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

if __name__ == "__main__":

__version__ = "1.0.2"
__version__ = "1.0.3"
__author__ = "https://github.com/northpowered"

ap = argparse.ArgumentParser()
Expand Down
6 changes: 3 additions & 3 deletions sla/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def _load_config(self, config_from_file):
)

# Appending template to device

with open(f"templates/{device['type']}.template") as template:
device["template"] = template
device["template"] = f"templates/{device['type']}.template"
# with open(f"templates/{device['type']}.template", "r") as template:
# device["template"] = template

# Parsing transport field in device object
try:
Expand Down
16 changes: 12 additions & 4 deletions sla/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from sla.logger import LG
from ping3 import ping
from sla.tracer import device_tracer, rtt_tracer
from io import TextIOWrapper


class Device:
Expand Down Expand Up @@ -41,6 +42,10 @@ def __get_rtt_remote(self, target: str):
"command": f"ping {target} detailed packets 1",
"connections": {"ssh": "eltex"},
},
"potok-km-122": {
"command": f"ping {target} count 1",
"connections": {"ssh": "generic"},
}
}
connection = {
"device_type": "generic",
Expand Down Expand Up @@ -73,13 +78,14 @@ def __get_rtt_remote(self, target: str):
LG.debug(f"Connected to {self.name} device")
result = hnd.send_command(command)
LG.debug(f"RTT command sent to {self.name} device")
fsm = textfsm.TextFSM(self.template)
with open(self.template, "r") as template:
fsm = textfsm.TextFSM(template)
output = fsm.ParseText(result)
try:
_ = float(output[0][0])
except IndexError:
except IndexError as ex:
_ = None
except Exception:
except Exception as ex:
_ = False
finally:
return _
Expand All @@ -89,6 +95,8 @@ def __get_rtt_remote(self, target: str):
LG.warning(f"Unreachable device. Connection with {self.name} failed")
except NetmikoAuthenticationException as error:
LG.warning(f"Authentication with {self.name} failed. Check credentials")
except Exception as ex:
print(ex)
else:
pass
finally:
Expand All @@ -112,7 +120,7 @@ def get_rtt(self, target: str):
span.set_attribute("device.type", self.type)
span.set_attribute("device.target", target)
rtt = int()
if self.type in ["m716", "cisco"]:
if self.type in ["m716", "cisco", "juniper", "eltex", "potok-km-122"]:
rtt = self.__get_rtt_remote(target)
elif self.type == "local":
rtt = self.__get_rtt_local(target)
Expand Down
5 changes: 5 additions & 0 deletions templates/potok-km-122.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Value RTT (.*)
Value TTL (.*)

Start
^(.*) TTL: ${TTL}, time: ${RTT} us -> Record

0 comments on commit 02bb9e7

Please sign in to comment.