LinuxMonitor 1.0.6__tar.gz → 1.1.1__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.1
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
@@ -52,6 +52,7 @@ List of 'check' functionalities:
52
52
  - Check services status and restart them if needed
53
53
  - Check certificates expiration and validity
54
54
  - Check last user connections IPs
55
+ - Check uptime (to inform if the server has been rebooted)
55
56
 
56
57
  Additionnal functionalities:
57
58
  - Get hostname, OS details, kernel version, server datetime, uptime
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: LinuxMonitor
3
- Version: 1.0.6
3
+ Version: 1.1.1
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
@@ -52,6 +52,7 @@ List of 'check' functionalities:
52
52
  - Check services status and restart them if needed
53
53
  - Check certificates expiration and validity
54
54
  - Check last user connections IPs
55
+ - Check uptime (to inform if the server has been rebooted)
55
56
 
56
57
  Additionnal functionalities:
57
58
  - Get hostname, OS details, kernel version, server datetime, uptime
@@ -24,6 +24,7 @@ List of 'check' functionalities:
24
24
  - Check services status and restart them if needed
25
25
  - Check certificates expiration and validity
26
26
  - Check last user connections IPs
27
+ - Check uptime (to inform if the server has been rebooted)
27
28
 
28
29
  Additionnal functionalities:
29
30
  - Get hostname, OS details, kernel version, server datetime, uptime
@@ -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
 
@@ -13,6 +13,7 @@ Non exhaustive list of features (available by using it in shell or in python scr
13
13
  - Check services status and restart them if needed
14
14
  - Check certificates expiration and validity
15
15
  - Check last user connections IPs
16
+ - Check uptime (to inform if the server has been rebooted)
16
17
 
17
18
  - Get hostname, OS details, kernel version, server datetime, uptime
18
19
  - Get connected users
@@ -28,7 +29,7 @@ __email__ = "quentin@comte-gaz.com"
28
29
  __license__ = "MIT License"
29
30
  __copyright__ = "Copyright Quentin Comte-Gaz (2024)"
30
31
  __python_version__ = "3.+"
31
- __version__ = "1.0.6 (2024/09/14)"
32
+ __version__ = "1.1.1 (2024/09/14)"
32
33
  __status__ = "Usable for any Linux project"
33
34
 
34
35
  import json
@@ -129,6 +130,14 @@ class LinuxMonitor:
129
130
  raise ValueError("The basic configuration must contain the 'critical_temperature_celsius' key")
130
131
  self.critical_temperature_celsius: float = basic_config.get('critical_temperature_celsius') # type: ignore
131
132
 
133
+ if 'critical_uptime_seconds' not in basic_config:
134
+ raise ValueError("The basic configuration must contain the 'critical_uptime_seconds' key")
135
+ self.critical_uptime_seconds: int = basic_config.get('critical_uptime_seconds') # type: ignore
136
+
137
+ if 'warning_uptime_seconds' not in basic_config:
138
+ raise ValueError("The basic configuration must contain the 'warning_uptime_seconds' key")
139
+ self.warning_uptime_seconds: int = basic_config.get('warning_uptime_seconds') # type: ignore
140
+
132
141
  # Get the scheduled tasks for issues configuration
133
142
  if self.allow_scheduled_tasks_check_for_issues:
134
143
  schedule_check_for_issues_config: Dict[str, Any] = self.config.get('scheduled_tasks_check_for_issues', {}) # type: ignore
@@ -634,9 +643,11 @@ class LinuxMonitor:
634
643
 
635
644
  return out_msg
636
645
 
637
- def get_uptime(self) -> str:
646
+ def check_uptime(self, display_only_if_critical: bool=False) -> str:
638
647
  """
639
- Get the system uptime.
648
+ Check the system uptime.
649
+
650
+ :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
651
 
641
652
  :return: A string containing the result message.
642
653
  """
@@ -652,25 +663,6 @@ class LinuxMonitor:
652
663
  # Date de démarrage du système
653
664
  boot_time: str = time.strftime("%d/%m/%Y %H:%M:%S", time.localtime(psutil.boot_time()))
654
665
 
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
666
  dispo: str = ""
675
667
  if years >= 1:
676
668
  dispo += f"{int(years)} year(s) "
@@ -684,11 +676,41 @@ class LinuxMonitor:
684
676
  dispo += f"{int(minutes)}min "
685
677
  if seconds >= 1:
686
678
  dispo += f"{int(seconds)}sec "
679
+ dispo += "ago"
687
680
 
688
- out_msg: str = (f"# 🕒 System availability 🕒\n"
689
- f"- {emoji} **{dispo}**(started on {boot_time})")
690
- logging.info(msg=out_msg)
681
+ out_msg: str = ""
682
+ if uptime_seconds < self.critical_uptime_seconds:
683
+ out_msg = f"- 🚨 **Server restarted recently**:\n- {dispo} (started on {boot_time})"
684
+ logging.warning(msg=out_msg)
685
+ elif not display_only_if_critical:
686
+ if uptime_seconds < self.warning_uptime_seconds:
687
+ out_msg = f"- ⚠️ **Server restarted recently**: {dispo} (started on {boot_time})"
688
+ logging.warning(msg=out_msg)
689
+ else:
690
+ # Funny emoji depending on uptime if everything is fine
691
+ emoji: str = ""
692
+ if years >= 2:
693
+ emoji = "🎂"
694
+ if years >= 1:
695
+ emoji = "🎉"
696
+ elif months >= 6:
697
+ emoji = "🥳"
698
+ elif months >= 1:
699
+ emoji = "😀"
700
+ elif days >= 1:
701
+ emoji = "🎊"
702
+ elif hours >= 1:
703
+ emoji = "👶"
704
+ elif minutes >= 20:
705
+ emoji = "🤔"
706
+ else:
707
+ emoji = "☢️"
708
+
709
+ out_msg = f"- {emoji} **{dispo}** (started on {boot_time})"
691
710
 
711
+ if out_msg != "":
712
+ out_msg = f"# 🕒 System availability 🕒\n{out_msg}"
713
+ logging.info(msg=out_msg)
692
714
  except Exception as e:
693
715
  out_msg = f"- ⚠️ **Error getting system uptime**:\n```sh\n{e}\n```"
694
716
  logging.exception(msg=out_msg)
@@ -1615,8 +1637,9 @@ class LinuxMonitor:
1615
1637
  datetime_last_user_logins_error_displayed: Optional[datetime] = None
1616
1638
  datetime_last_port_error_displayed: Optional[datetime] = None
1617
1639
  datetime_last_services_error_displayed: Optional[datetime] = None
1640
+ need_to_check_uptime: bool = True # No need to check uptime every time (since once ok, it can't be wrong)
1618
1641
 
1619
- if not self.start_scheduled_task_show_info_immediately:
1642
+ if not self.start_scheduled_tasks_immediately:
1620
1643
  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...")
1621
1644
  await asyncio.sleep(delay=self.duration_in_sec_wait_between_each_schedule_task_execution)
1622
1645
 
@@ -1860,6 +1883,19 @@ class LinuxMonitor:
1860
1883
  datetime_last_cpu_temperature_error_displayed = None
1861
1884
  else:
1862
1885
  logging.info(msg="- ✅ CPU temperature is OK.")
1886
+
1887
+ # Uptime
1888
+ if is_private:
1889
+ if need_to_check_uptime:
1890
+ msg = self.check_uptime(display_only_if_critical=True)
1891
+ need_to_check_uptime = False
1892
+ if msg != "":
1893
+ logging.warning(msg=msg)
1894
+ if out_msg != "":
1895
+ out_msg += "\n"
1896
+ out_msg += msg
1897
+ else:
1898
+ logging.info(msg="- ✅ Uptime is OK.")
1863
1899
  except Exception as e:
1864
1900
  out_msg = f"**Internal error during periodic server check task**:\n```sh\n{e}\n```"
1865
1901
  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.1",
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