sysview-py 0.4.2__tar.gz → 0.4.4__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.2
3
+ Version: 0.4.4
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.2"
3
+ version = "0.4.4"
4
4
  description = "Add your description here"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -90,7 +90,7 @@ class SysviewDB:
90
90
  self._connection.commit()
91
91
 
92
92
  def get_last_changed_item(self, item):
93
- sql = f"SELECT report_id,raw_item FROM items WHERE command = '{item.command}' AND hostname = '{item.host}' AND NOT status = '{item.status} AND report_id < {item.report_id}' ORDER BY rowid DESC LIMIT 1"
93
+ sql = f"SELECT report_id,raw_item FROM items WHERE command = '{item.command}' AND hostname = '{item.host}' AND report_id < {item.report_id} AND NOT status = '{item.status}' ORDER BY rowid DESC LIMIT 1"
94
94
  last_changed_item = self._cursor.execute(sql).fetchone()
95
95
  if last_changed_item is not None:
96
96
  report_id = last_changed_item[0]
@@ -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}
@@ -97,12 +98,16 @@ class ReportItem:
97
98
  def name(self):
98
99
  result = self.command
99
100
  if len(result) > self.max_name_length:
100
- result = result[: self.max_name_length] + "..."
101
+ result = result[: self.max_name_length]
101
102
  return result
102
103
 
104
+ @property
105
+ def filename(self):
106
+ return slugify(self.name)
107
+
103
108
  @property
104
109
  def url_path(self):
105
- return f"{self.report_type}_{self.id}.html"
110
+ return f"{self.report_type}_{self.filename}.html"
106
111
 
107
112
  @property
108
113
  def status(self):
@@ -78,13 +78,14 @@ class Sysview:
78
78
  html = env.get_template("service.html").render(
79
79
  item=item,
80
80
  title=host.name,
81
+ subtitle=item.name,
81
82
  active="Services",
82
83
  path="../../",
83
84
  auto_refresh=False,
84
85
  item_history=item_history,
85
86
  )
86
- html_path = host_dir / f"{item.report_type}_{item.id}.html"
87
- raw_path = host_dir / f"{item.report_type}_{item.id}.txt"
87
+ html_path = host_dir / f"{item.report_type}_{item.filename}.html"
88
+ raw_path = host_dir / f"{item.report_type}_{item.filename}.txt"
88
89
  with open(html_path, "w") as f:
89
90
  f.write(html)
90
91
  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