This commit is contained in:
2024-01-02 13:54:04 +01:00
parent ff2d8296f3
commit c487c769b0

View File

@@ -67,7 +67,7 @@ class SMARTStatus(db.Model):
timestamp = Column(Integer, primary_key=True) timestamp = Column(Integer, primary_key=True)
power_cycles = Column(Integer) power_cycles = Column(Integer)
temperatur = Column(Integer) temperatur = Column(Integer)
avail_spare = Column(Integer) available_spare = Column(Integer)
unsafe_shutdowns = Column(Integer) unsafe_shutdowns = Column(Integer)
critical_warning = Column(Integer) critical_warning = Column(Integer)
model_number = Column(String) model_number = Column(String)
@@ -338,30 +338,53 @@ def record_and_check_smart(service, timestamp, smart):
# record the status # # record the status #
smart_status = SMARTStatus(service=service.service_name, timestamp=timestamp, smart_status = SMARTStatus(service=service.service_name, timestamp=timestamp,
temperatur=health_info["temperature"] temperature=health_info["temperature"]
critical_warning=health_info["critical_warning"] critical_warning=health_info["critical_warning"]
unsafe_shutdowns=health_info["unsafe_shutdowns"] unsafe_shutdowns=health_info["unsafe_shutdowns"]
power_cycles=health_info["power_cycles"] power_cycles=health_info["power_cycles"]
power_on_hours=health_info["power_on_hours"] power_on_hours=health_info["power_on_hours"]
avail_spare=health_info.get("available_spare") available_spare=health_info.get("available_spare")
model_number=smart.get("model_name"]) model_number=smart.get("model_name"]))
db.add(smart_status) db.add(smart_status)
db.commit() db.commit()
# check the status # # check the status #
# temp average > X smart_last_query = db.session.query(SMARTStatus)
# critial != 0 smart_last_query = smart_last_query.filter(SMARTStatus.service_name==service.service_name)
# unsafe_shutdowns +1 smart_last = smart_last_query.order_by(sqlalchemy.desc(SMARTStatus.timestamp)).first()
# powercycles > 2000 = 0 smart_second_last = smart_last_query.order_by(sqlalchemy.desc(SMARTStatus.timestamp)).offset(1).first()
# poweron hours > 20000
# available_spare -10 pro 6months
# available_spare <50
# TODO
db.query(SMARTStatus).filter(SMARTStatus.timestamp >
smartanalysis.analyse(smartanalysis
return (text, status) # last record (max 6 months ago) #
timestampt_minus_6m = datetime.datetime.now() - datetime.timedelta(months=6)
smart_old_query = smart_last_query.filter(SMARTStatus.timestamp > timestampt_minus_6m.timestamp())
smart_old = smart_old_query.order_by(sqlalchemy.asc(SMARTStatus.timestamp)).first()
# temp max > X #
if smart_last.temperature > 50:
return ("Disk Temperatur {}".format(smart_last.temperature), "CRITICAL")
# critial != 0 #
if smart_last_query.critial != 0:
return ("SMART reports disk critical => oO better do something about this", "CRITICAL")
# unsafe_shutdowns +1 #
if smart_second_last.unsafe_shutdowns - smart_last.unsafe_shutdowns >= 1:
return ("Disk had {} unsafe shutdown".format(smart_last.unsafe_shutdowns), "WARNING")
# available_spare -10 pro 6months #
spare = smart_old.available_spare - smart_last.available_spare
if spare >= 10:
return ("Strong degration in SSD spare space ({} in under 6 months)".format(
spare_change, "WARNING")
# available_spare #
if smart_last.available_spare < 50:
return ("Available SSD spare <50 ({})".format(spare_change, "WARNING")
elif smart_last.available_spare <25:
return ("Available SSD spare <25 ({}) YOUR DISK WILL DIE SOON".format(spare_change, "CRITIAL")
return ("OK", "")
def create_app(): def create_app():