LinuxMonitor 1.0.6__tar.gz → 1.1.0__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.1
2
2
  Name: LinuxMonitor
3
- Version: 1.0.6
3
+ Version: 1.1.0
4
4
  Summary: Get information and warning status of Linux server like service, port, ping, ssl certificate, disk/folder/cpu/ram/swap usage, ip connection, ... (Python and shell library, Linux ONLY)
5
5
  Home-page: https://github.com/QuentinCG/Linux-Monitor-Python-Library
6
6
  Author: Quentin Comte-Gaz
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: LinuxMonitor
3
- Version: 1.0.6
3
+ Version: 1.1.0
4
4
  Summary: Get information and warning status of Linux server like service, port, ping, ssl certificate, disk/folder/cpu/ram/swap usage, ip connection, ... (Python and shell library, Linux ONLY)
5
5
  Home-page: https://github.com/QuentinCG/Linux-Monitor-Python-Library
6
6
  Author: Quentin Comte-Gaz
@@ -79,7 +79,7 @@ def main() -> None:
79
79
  out_msg: str = monitoring.get_hostname() + "\n"
80
80
  out_msg += monitoring.get_os_details() + "\n"
81
81
  out_msg += monitoring.get_kernel_version() + "\n"
82
- out_msg += monitoring.get_uptime() + "\n"
82
+ out_msg += monitoring.check_uptime(display_only_if_critical=False) + "\n"
83
83
  out_msg += monitoring.get_server_datetime()
84
84
  print(out_msg)
85
85
 
@@ -28,7 +28,7 @@ __email__ = "quentin@comte-gaz.com"
28
28
  __license__ = "MIT License"
29
29
  __copyright__ = "Copyright Quentin Comte-Gaz (2024)"
30
30
  __python_version__ = "3.+"
31
- __version__ = "1.0.6 (2024/09/14)"
31
+ __version__ = "1.1.0 (2024/09/14)"
32
32
  __status__ = "Usable for any Linux project"
33
33
 
34
34
  import json
@@ -129,6 +129,14 @@ class LinuxMonitor:
129
129
  raise ValueError("The basic configuration must contain the 'critical_temperature_celsius' key")
130
130
  self.critical_temperature_celsius: float = basic_config.get('critical_temperature_celsius') # type: ignore
131
131
 
132
+ if 'critical_uptime_seconds' not in basic_config:
133
+ raise ValueError("The basic configuration must contain the 'critical_uptime_seconds' key")
134
+ self.critical_uptime_seconds: int = basic_config.get('critical_uptime_seconds') # type: ignore
135
+
136
+ if 'warning_uptime_seconds' not in basic_config:
137
+ raise ValueError("The basic configuration must contain the 'warning_uptime_seconds' key")
138
+ self.warning_uptime_seconds: int = basic_config.get('warning_uptime_seconds') # type: ignore
139
+
132
140
  # Get the scheduled tasks for issues configuration
133
141
  if self.allow_scheduled_tasks_check_for_issues:
134
142
  schedule_check_for_issues_config: Dict[str, Any] = self.config.get('scheduled_tasks_check_for_issues', {}) # type: ignore
@@ -634,9 +642,11 @@ class LinuxMonitor:
634
642
 
635
643
  return out_msg
636
644
 
637
- def get_uptime(self) -> str:
645
+ def check_uptime(self, display_only_if_critical: bool=False) -> str:
638
646
  """
639
- Get the system uptime.
647
+ Check the system uptime.
648
+
649
+ :param display_only_if_critical: If True, the string result will only be returned if uptime is less than the critical uptime defined in the configuration.
640
650
 
641
651
  :return: A string containing the result message.
642
652
  """
@@ -652,25 +662,6 @@ class LinuxMonitor:
652
662
  # Date de démarrage du système
653
663
  boot_time: str = time.strftime("%d/%m/%Y %H:%M:%S", time.localtime(psutil.boot_time()))
654
664
 
655
- # Funny emoji depending on uptime
656
- emoji: str = ""
657
- if years >= 2:
658
- emoji = "🎂"
659
- if years >= 1:
660
- emoji = "🎉"
661
- elif months >= 6:
662
- emoji = "🥳"
663
- elif months >= 1:
664
- emoji = "😀"
665
- elif days >= 1:
666
- emoji = "🎊"
667
- elif hours >= 1:
668
- emoji = "👶"
669
- elif minutes >= 20:
670
- emoji = "🤔"
671
- else:
672
- emoji = "☢️"
673
-
674
665
  dispo: str = ""
675
666
  if years >= 1:
676
667
  dispo += f"{int(years)} year(s) "
@@ -685,10 +676,37 @@ class LinuxMonitor:
685
676
  if seconds >= 1:
686
677
  dispo += f"{int(seconds)}sec "
687
678
 
688
- out_msg: str = (f"# 🕒 System availability 🕒\n"
689
- f"- {emoji} **{dispo}**(started on {boot_time})")
690
- logging.info(msg=out_msg)
679
+ out_msg: str = ""
680
+ if uptime_seconds < self.critical_uptime_seconds:
681
+ out_msg = f"- 🚨 **Server restarted recently**:\n- {dispo}(started on {boot_time})"
682
+ elif not display_only_if_critical:
683
+ if uptime_seconds < self.warning_uptime_seconds:
684
+ out_msg = f"- ⚠️ **Server restarted recently**: {dispo}(started on {boot_time})"
685
+ else:
686
+ # Funny emoji depending on uptime if everything is fine
687
+ emoji: str = ""
688
+ if years >= 2:
689
+ emoji = "🎂"
690
+ if years >= 1:
691
+ emoji = "🎉"
692
+ elif months >= 6:
693
+ emoji = "🥳"
694
+ elif months >= 1:
695
+ emoji = "😀"
696
+ elif days >= 1:
697
+ emoji = "🎊"
698
+ elif hours >= 1:
699
+ emoji = "👶"
700
+ elif minutes >= 20:
701
+ emoji = "🤔"
702
+ else:
703
+ emoji = "☢️"
704
+
705
+ out_msg = f"- {emoji} **{dispo}**(started on {boot_time})"
691
706
 
707
+ if out_msg != "":
708
+ out_msg = f"# 🕒 System availability 🕒\n{out_msg}"
709
+ logging.info(msg=out_msg)
692
710
  except Exception as e:
693
711
  out_msg = f"- ⚠️ **Error getting system uptime**:\n```sh\n{e}\n```"
694
712
  logging.exception(msg=out_msg)
@@ -1615,6 +1633,7 @@ class LinuxMonitor:
1615
1633
  datetime_last_user_logins_error_displayed: Optional[datetime] = None
1616
1634
  datetime_last_port_error_displayed: Optional[datetime] = None
1617
1635
  datetime_last_services_error_displayed: Optional[datetime] = None
1636
+ need_to_check_uptime: bool = True # No need to check uptime every time (since once ok, it can't be wrong)
1618
1637
 
1619
1638
  if not self.start_scheduled_task_show_info_immediately:
1620
1639
  logging.info(msg=f"Waiting for {self.duration_in_sec_wait_between_each_schedule_task_execution} seconds before starting the execution of {'private' if is_private else 'public'} scheduled tasks...")
@@ -1860,6 +1879,19 @@ class LinuxMonitor:
1860
1879
  datetime_last_cpu_temperature_error_displayed = None
1861
1880
  else:
1862
1881
  logging.info(msg="- ✅ CPU temperature is OK.")
1882
+
1883
+ # Uptime
1884
+ if is_private:
1885
+ if need_to_check_uptime:
1886
+ msg = self.check_uptime(display_only_if_critical=True)
1887
+ need_to_check_uptime = False
1888
+ if msg != "":
1889
+ logging.warning(msg=msg)
1890
+ if out_msg != "":
1891
+ out_msg += "\n"
1892
+ out_msg += msg
1893
+ else:
1894
+ logging.info(msg="- ✅ Uptime is OK.")
1863
1895
  except Exception as e:
1864
1896
  out_msg = f"**Internal error during periodic server check task**:\n```sh\n{e}\n```"
1865
1897
  logging.exception(msg=out_msg)
@@ -6,7 +6,7 @@ with io.open(file='README.md', mode='r', encoding='utf-8') as readme_file:
6
6
 
7
7
  setup(
8
8
  name="LinuxMonitor",
9
- version="1.0.6",
9
+ version="1.1.0",
10
10
  description="Get information and warning status of Linux server like service, port, ping, ssl certificate, disk/folder/cpu/ram/swap usage, ip connection, ... (Python and shell library, Linux ONLY)",
11
11
  long_description=readme,
12
12
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes