sysview-py 0.4.3__tar.gz → 0.4.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: sysview-py
3
- Version: 0.4.3
3
+ Version: 0.4.5
4
4
  Summary: Add your description here
5
5
  Author: Michael Wilson
6
6
  Author-email: Michael Wilson <mw@1wilson.org>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sysview-py"
3
- version = "0.4.3"
3
+ version = "0.4.5"
4
4
  description = "Add your description here"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -0,0 +1,18 @@
1
+ import unicodedata
2
+ import re
3
+
4
+ def slugify(value, allow_unicode=False):
5
+ """
6
+ Taken from https://github.com/django/django/blob/master/django/utils/text.py
7
+ Convert to ASCII if 'allow_unicode' is False. Convert spaces or repeated
8
+ dashes to single dashes. Remove characters that aren't alphanumerics,
9
+ underscores, or hyphens. Convert to lowercase. Also strip leading and
10
+ trailing whitespace, dashes, and underscores.
11
+ """
12
+ value = str(value)
13
+ if allow_unicode:
14
+ value = unicodedata.normalize('NFKC', value)
15
+ else:
16
+ value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
17
+ value = re.sub(r'[^\w\s-]', '', value.lower())
18
+ return re.sub(r'[-\s]+', '-', value).strip('-_')
@@ -1,5 +1,6 @@
1
1
  import hashlib
2
2
  from datetime import datetime, timedelta
3
+ from .helpers import slugify
3
4
 
4
5
 
5
6
  status_map = {"UNKNOWN": 3, "CRITICAL": 2, "WARNING": 1, "OK": 0}
@@ -75,6 +76,7 @@ class ReportItem:
75
76
  host=None,
76
77
  report_type=None,
77
78
  report_id=None,
79
+ is_only_item=False
78
80
  ):
79
81
  self.raw_item = raw_item
80
82
  self.command = command
@@ -85,6 +87,7 @@ class ReportItem:
85
87
  self.report_type = report_type
86
88
  self.report_id = report_id
87
89
  self.host = host
90
+ self.is_only_item = is_only_item
88
91
 
89
92
  def __repr__(self):
90
93
  return f"ReportItem(command={self.command}, status={self.status})"
@@ -96,13 +99,19 @@ class ReportItem:
96
99
  @property
97
100
  def name(self):
98
101
  result = self.command
99
- if len(result) > self.max_name_length:
100
- result = result[: self.max_name_length] + "..."
102
+ if self.is_only_item:
103
+ result = self.report_type
104
+ elif len(result) > self.max_name_length:
105
+ result = result[: self.max_name_length]
101
106
  return result
102
107
 
108
+ @property
109
+ def filename(self):
110
+ return slugify(self.name)
111
+
103
112
  @property
104
113
  def url_path(self):
105
- return f"{self.report_type}_{self.id}.html"
114
+ return f"{self.report_type}_{self.filename}.html"
106
115
 
107
116
  @property
108
117
  def status(self):
@@ -215,4 +224,6 @@ class Report:
215
224
  item.parse()
216
225
  self.items.append(item)
217
226
  self.items.sort(key=lambda item: item.status_code, reverse=True)
227
+ if len(self.items) == 1:
228
+ self.items[0].is_only_item = True
218
229
  self.raw_report = "\n".join(raw_report)
@@ -58,8 +58,6 @@ class Sysview:
58
58
  env = Environment(
59
59
  loader=PackageLoader("sysview_py"), autoescape=select_autoescape()
60
60
  )
61
- for host in self.hosts:
62
- host.all_items
63
61
  for host in self.hosts:
64
62
  html = env.get_template("card_view.html").render(
65
63
  items=host.all_items,
@@ -78,13 +76,14 @@ class Sysview:
78
76
  html = env.get_template("service.html").render(
79
77
  item=item,
80
78
  title=host.name,
79
+ subtitle=item.name,
81
80
  active="Services",
82
81
  path="../../",
83
82
  auto_refresh=False,
84
83
  item_history=item_history,
85
84
  )
86
- html_path = host_dir / f"{item.report_type}_{item.id}.html"
87
- raw_path = host_dir / f"{item.report_type}_{item.id}.txt"
85
+ html_path = host_dir / f"{item.report_type}_{item.filename}.html"
86
+ raw_path = host_dir / f"{item.report_type}_{item.filename}.txt"
88
87
  with open(html_path, "w") as f:
89
88
  f.write(html)
90
89
  with open(raw_path, "w") as f:
@@ -25,5 +25,8 @@
25
25
  {% endif %}
26
26
  </nav>
27
27
  <h2>{{ title }}</h2>
28
+ {% if subtitle is defined %}
29
+ <p>{{ subtitle }}</p>
30
+ {% endif %}
28
31
  </header>
29
32
  <main>
@@ -2,10 +2,14 @@
2
2
  <nav>
3
3
  <a href="host.html">Show host</a>
4
4
  |
5
- <a href="{{ item.report_type }}_{{ item.id }}.txt">Raw report</a>
5
+ <a href="{{ item.report_type }}_{{ item.filename }}.txt">Raw report</a>
6
6
  </nav>
7
7
  </table>
8
8
  <pre id="{{item.status}}">{{ item.status }}: {{ item.status_text }}</pre>
9
+ <details>
10
+ <summary>full report</summary>
11
+ <pre>{{ item.raw_item }}</pre>
12
+ </details>
9
13
  <i>Received: {{ item.date }}</i>
10
14
  {% if item_history %}
11
15
  <h3>History</h3>
File without changes