17 Commits

Author SHA1 Message Date
52569c7687 fix: remove obsolete qemu action
Some checks failed
ci / docker (push) Failing after 9s
2025-11-25 12:07:43 +01:00
d70a37f42c whitespace: fix trailing spaces
Some checks failed
ci / docker (push) Failing after 2m3s
2025-11-25 00:03:28 +01:00
8d6590364f fix: set model number as additional primary key
Some checks failed
ci / docker (push) Has been cancelled
2025-11-24 17:14:26 +01:00
dd7a81fd0f feat: allow configure database url via env 2025-11-24 17:14:22 +01:00
7b5f28651b update: add build schedule
Some checks failed
ci / docker (push) Failing after 5s
2024-09-27 17:09:55 +02:00
a7f4788291 change: increase temp warning to 60degC 2024-02-05 20:40:55 +01:00
74b48a2477 fix: run as Administratoren to prevent window 2024-01-12 05:35:01 +01:00
18f8436078 fix: broke CSS background on some displays 2024-01-03 17:20:38 +01:00
3df3ddb08e fix: fallback on smart_status for critical bit 2024-01-03 17:05:05 +01:00
72e0210d26 feat: add Perc_Avail_Resrvd_Space to support metrics 2024-01-03 16:55:36 +01:00
edc454f154 feat: windows hourly task snippet 2024-01-03 16:40:10 +01:00
824c108678 fix: handle second_last in first request 2024-01-03 15:16:59 +01:00
08fc17efe0 fix: smart record examples before first request 2024-01-03 14:53:25 +01:00
683ebefbb0 feat: add SMART monitoring support 2024-01-03 14:41:11 +01:00
0842818cbc fix: dont change token on modification 2024-01-03 14:40:57 +01:00
d6ea667733 fix: skip icinga host creation if not configured 2024-01-03 14:39:17 +01:00
935bfa3eef fix: skip icinga connection if not configured 2024-01-03 14:37:50 +01:00
5 changed files with 34 additions and 12 deletions

View File

@@ -4,6 +4,8 @@ on:
push:
branches:
- "master"
schedule:
- cron: "0 2 * * 0"
jobs:
docker:
@@ -14,9 +16,6 @@ jobs:
-
name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

View File

@@ -29,7 +29,7 @@ import smarttools
app = flask.Flask("Icinga Report In Gateway")
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.sqlite'
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('SQLALCHEMY_DATABASE_URI') or 'sqlite:///database.sqlite'
app.config['JSON_CONFIG_FILE'] = 'services.json'
app.config['JSON_CONFIG_DIR'] = 'config'
db = SQLAlchemy(app)
@@ -65,12 +65,12 @@ class SMARTStatus(db.Model):
service = Column(String, primary_key=True)
timestamp = Column(Integer, primary_key=True)
model_number = Column(String, primary_key=True)
power_cycles = Column(Integer)
temperature = Column(Integer)
available_spare = Column(Integer)
unsafe_shutdowns = Column(Integer)
critical_warning = Column(Integer)
model_number = Column(String)
power_cycles = Column(Integer)
power_on_hours = Column(Integer)
wearleveling_count = Column(Integer)
@@ -342,7 +342,7 @@ def default():
text, status = record_and_check_smart(verifiedServiceObj,
timestamp, smart)
status = Status(service=service, timestamp=timestamp, status=status,
status = Status(service=service, timestamp=timestamp, status=status,
info_text=text)
db.session.merge(status)
db.session.commit()
@@ -396,7 +396,7 @@ def record_and_check_smart(service, timestamp, smart):
return ("SMART report prefail disk (wear_level < 20%)", "CRITICAL")
# temp max > X #
if smart_last.temperature > 50:
if smart_last.temperature > 60:
return ("Disk Temperatur {}".format(smart_last.temperature), "CRITICAL")
# available_SSD spare #
@@ -412,11 +412,12 @@ def record_and_check_smart(service, timestamp, smart):
spare_change), "WARNING")
# unsafe_shutdowns +1 #
if smart_second_last.unsafe_shutdowns - smart_last.unsafe_shutdowns >= 1:
if(smart_second_last and
smart_second_last.unsafe_shutdowns - smart_last.unsafe_shutdowns >= 1):
return ("Disk had {} unsafe shutdowns".format(smart_last.unsafe_shutdowns),
"WARNING")
return ("", "OK")
return ("{} - no problems detected".format(smart_last.model_number), "OK")
def create_app():

View File

@@ -34,6 +34,8 @@ def normalize(smart):
elif name == "power_on_hours":
target_name = "power_on_hours"
use_raw = True
elif name == "perc_avail_resrvd_space":
target_name = "available_spare"
# check if metric should be recorded #
if target_name in ret:
@@ -46,4 +48,7 @@ def normalize(smart):
ret[target_name] = value
if ret["critical_warning"] == 0 and "smart_status" in smart:
ret["critical_warning"] = int(not smart["smart_status"]["passed"])
return ret

View File

@@ -1,5 +1,6 @@
body{
background: radial-gradient(ellipse at center, #47918a 0%, #0b3161 100%);
background-attachment: fixed;
color: aliceblue !important;
}

View File

@@ -83,13 +83,13 @@
</div>
{% endif %}
{% if smart %}
{% if service.special_type == "SMART" %}
<h5 class="clear my-4">Linux</h5>
{% else %}
<h5 class="clear my-4">Curl</h5>
{% endif %}
<div class="ml-3 example">
{% if smart %}
{% if service.special_type == "SMART" %}
SMART='{ <br>
<div class="example-indent">
"service" : "{{ service.service }}", <br>
@@ -115,7 +115,7 @@
{% endif %}
</div>
{% if smart %}
{% if service.special_type == "SMART" %}
<h5 class="my-4">Windows</h5>
<div class="ml-3 example">
$SMART = @{ <br>
@@ -128,6 +128,22 @@
} | ConvertTo-Json<br><br>
Invoke-RestMethod -TimeoutSec 2 -Uri "{{ flask.request.url_root.replace("http://", "https://" )}}report" -Method Post -Headers @{"Content-Type"="application/json"} -Body $SMART
</div>
<!-- register task example -->
<h5 class="my-4">Windows Task (requires Admin-Powershell)</h5>
<div class="ml-3 example">
$ScriptPath = Join-Path $HOME -ChildPath "smart_monitor.ps1" <br>
echo '$SMART = @{ <br>
<div class="example-indent">
service = "{{ service.service }}"<br>
token = "{{ service.token }}"<br>
status = "N/A"<br>
smart = "$(smartctl -a C: --json | Out-String)"<br>
</div>
} | ConvertTo-Json<br><br>
Invoke-RestMethod -TimeoutSec 2 -Uri "{{ flask.request.url_root.replace("http://", "https://" )}}report" -Method Post -Headers @{"Content-Type"="application/json"} -Body $SMART' &gt; $ScriptPath <br>
schtasks /create /tn SMART_Monitor /tr "powershell.exe -executionpolicy bypass -File '$ScriptPath'" /sc hourly /mo 1 /ru "Administratoren"<br>
echo "Done" <br>
</div>
{% else %}
<h5 class="my-4">Python</h5>
<div class="ml-3 example">