Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit for v1-alpha-2 release #4

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ Tensu is a TUI (curses) based program for interacting with SensuGo Enterprises'
![screenshot](/misc/screenshot-2.jpg "Screenshot")

# Installation

Requirements:

* Python 3.8, 3.9, 3.10

```
pip3 install -r requirements.txt
```
Expand Down
2 changes: 1 addition & 1 deletion app/columnheader.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def draw(self) -> None:
curr_x=curr_x,
add_back_pct=add_back_pct,
self_w=self.w,
column_grow_pct=column_grow_pct
column_grow_pct=column_grow_pct,
)

self.win.addstr(0, curr_x, column_name, self.theme)
Expand Down
52 changes: 43 additions & 9 deletions app/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@ class ViewOptions:
ALL = "ALL"
SILENCED = "SILENCED"

def __eq__(self, other):
return any(
[
other == getattr(self, item)
for item in filter(lambda x: (not x.startswith("_")), dir(self))
]
)


class SortOptions:
SORT_BY_TIMESTAMP = "sort_by_timestamp"
SORT_BY_LAST_OK = "sort_by_last_ok"
SORT_BY_ENTITY = "sort_by_entity"
SORT_BY_ISSUED = "sort_by_issued"
SORT_BY_SEVERITY = "sort_by_severity"

@classmethod
def all(cls):
return list(
i.lower() for i in filter(lambda x: x.startswith("SORT_BY"), dir(cls))
)


class Filters:
"""Defines string values for various filters."""
Expand All @@ -30,15 +52,13 @@ class Filters:
SILENCED_CREATOR_REGEX = "CREATOR_REGEX"
SILENCED_REASON_REGEX = "REASON_REGEX"


DEFAULT_KEYMAP = {
ViewOptions.NOT_PASSING: {"label": "Alt+1", "modifier": 27, "key": 49},
ViewOptions.ALL: {"label": "Alt+2", "modifier": 27, "key": 50},
ViewOptions.SILENCED: {"label": "Alt+3", "modifier": 27, "key": 51},
Filters.EVENT_HOST_REGEX: {"label": "Ctrl+F", "key": 6},
Filters.EVENT_CHECK_REGEX: {"label": "Ctrl+N", "key": 14},
Filters.EVENT_OUTPUT_REGEX: {"label": "Ctrl+O", "key": 15},
}
def __eq__(self, other):
return any(
[
other == getattr(self, item)
for item in filter(lambda x: (not x.startswith("_")), dir(self))
]
)


class AuthenticationOptions:
Expand All @@ -54,6 +74,18 @@ class InternalDefaults:

APPNAME = "Tensu"

DEFAULT_KEYMAP = {
ViewOptions.NOT_PASSING: {"label": "Alt+1", "modifier": 27, "key": 49},
ViewOptions.ALL: {"label": "Alt+2", "modifier": 27, "key": 50},
ViewOptions.SILENCED: {"label": "Alt+3", "modifier": 27, "key": 51},
Filters.SILENCED_NAME_REGEX: {"label": "Ctrl+F", "key": 6},
Filters.SILENCED_CREATOR_REGEX: {"label": "Ctrl+F", "key": 15},
Filters.SILENCED_REASON_REGEX: {"label": "Ctrl+F", "key": 18},
Filters.EVENT_HOST_REGEX: {"label": "Ctrl+F", "key": 6},
Filters.EVENT_CHECK_REGEX: {"label": "Ctrl+N", "key": 14},
Filters.EVENT_OUTPUT_REGEX: {"label": "Ctrl+O", "key": 15},
}

STATE = {
"status_message": "Welcome to Tensu!",
"status_is_error": False,
Expand All @@ -62,4 +94,6 @@ class InternalDefaults:
"fetch_interval_ms": 700,
"view": ViewOptions.NOT_PASSING,
"keymap": DEFAULT_KEYMAP,
"sort": SortOptions.SORT_BY_TIMESTAMP,
"sort_orders": {x: False for x in SortOptions.all()},
}
1 change: 1 addition & 0 deletions app/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
("Hostname", 30, 0.10),
("Check Name", 32, 0.10),
("Output", 3, 0.80),
("Timestamp", 20, 0),
("Issued", 19, 0),
)
# Column Name, Minimum Width, Grow Percent
Expand Down
7 changes: 7 additions & 0 deletions app/eventinfowindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ def retrieve_and_draw(self) -> None:

datas = (
("id:", self.item["id"]),
(
"Timestamp:",
"{} ({})".format(
self.item["timestamp"],
datetime.fromtimestamp(self.item["timestamp"]),
),
),
("Entity:", self.item["entity"]["metadata"]["name"]),
("Proxy Entity:", self.item["check"]["proxy_entity_name"]),
("Check:", self.item["check"]["metadata"]["name"]),
Expand Down
5 changes: 5 additions & 0 deletions app/eventitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def draw(self) -> None:
name = self.event["check"]["metadata"]["name"]
hostname = self.event["entity"]["metadata"]["name"]
issued = self.event["check"]["issued"]
timestamp = self.event["timestamp"]
output = self.event["check"]["output"]
is_silenced = self.event["check"]["is_silenced"]

Expand Down Expand Up @@ -81,6 +82,9 @@ def draw(self) -> None:
check_state = "unknown"

issued_str = f"{datetime.fromtimestamp(issued).strftime('%Y-%m-%d %H:%M:%S')}"
timestamp_str = (
f"{datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')}"
)

if is_silenced:
if self.selected:
Expand All @@ -97,6 +101,7 @@ def draw(self) -> None:
(hostname, hostname_theme),
(name, theme),
(output, output_theme),
(timestamp_str, theme),
(issued_str, theme),
)
curr_x = 0
Expand Down
2 changes: 1 addition & 1 deletion app/listselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, state: dict, stdscr, items: dict, title: str) -> None:
# the title. Whichever is longest.
w = (
max(len(sorted(items, key=lambda k: len(k), reverse=True)[0]), len(title))
+ 2
+ 4
)
super().__init__(
h,
Expand Down
4 changes: 4 additions & 0 deletions app/listselectitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def draw(self) -> None:
theme = curses.color_pair(ColorPairs.BUTTON_TEXT_SELECTED)
else:
theme = curses.color_pair(ColorPairs.BUTTON_TEXT)
self.logger.debug(
"text_w={}, list_select_item_w={}, parent_w={}, attempting to draw {}"
.format(len(self.text), self.w, self.parent.w, self.text)
)
self.color(theme)
self.win.addstr(0, 0, self.text)
self.win.refresh()
7 changes: 7 additions & 0 deletions app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
class Utils:
"""A helper class."""

@staticmethod
def direction_icon(b: bool) -> str:
if b is False:
return "▲"
else:
return "▼"

@staticmethod
def current_milli_time() -> int:
"""Get the current time as epoch in milliseconds."""
Expand Down
2 changes: 1 addition & 1 deletion app/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.

VERSION = "v1-alpha"
VERSION = "v1-alpha-2"
Loading