mirror of
https://github.com/FAUSheppy/icinga-webhook-gateway
synced 2025-12-08 16:28:42 +01:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 52569c7687 | |||
| d70a37f42c | |||
| 8d6590364f | |||
| dd7a81fd0f | |||
| 7b5f28651b | |||
| a7f4788291 | |||
| 74b48a2477 | |||
| 18f8436078 | |||
| 3df3ddb08e | |||
| 72e0210d26 | |||
| edc454f154 | |||
| 824c108678 | |||
| 08fc17efe0 | |||
| 683ebefbb0 | |||
| 0842818cbc | |||
| d6ea667733 | |||
| 935bfa3eef |
5
.github/workflows/main.yaml
vendored
5
.github/workflows/main.yaml
vendored
@@ -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
|
||||
|
||||
13
server.py
13
server.py
@@ -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():
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
body{
|
||||
background: radial-gradient(ellipse at center, #47918a 0%, #0b3161 100%);
|
||||
background-attachment: fixed;
|
||||
color: aliceblue !important;
|
||||
}
|
||||
|
||||
|
||||
@@ -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' > $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">
|
||||
|
||||
Reference in New Issue
Block a user