LinuxMonitor 1.2.2__tar.gz → 1.2.5__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.
- {linuxmonitor-1.2.2 → linuxmonitor-1.2.5/LinuxMonitor.egg-info}/PKG-INFO +1 -1
- {linuxmonitor-1.2.2/LinuxMonitor.egg-info → linuxmonitor-1.2.5}/PKG-INFO +1 -1
- {linuxmonitor-1.2.2 → linuxmonitor-1.2.5}/linuxmonitor/linuxmonitor.py +27 -15
- {linuxmonitor-1.2.2 → linuxmonitor-1.2.5}/setup.py +1 -1
- {linuxmonitor-1.2.2 → linuxmonitor-1.2.5}/LICENSE.md +0 -0
- {linuxmonitor-1.2.2 → linuxmonitor-1.2.5}/LinuxMonitor.egg-info/SOURCES.txt +0 -0
- {linuxmonitor-1.2.2 → linuxmonitor-1.2.5}/LinuxMonitor.egg-info/dependency_links.txt +0 -0
- {linuxmonitor-1.2.2 → linuxmonitor-1.2.5}/LinuxMonitor.egg-info/requires.txt +0 -0
- {linuxmonitor-1.2.2 → linuxmonitor-1.2.5}/LinuxMonitor.egg-info/top_level.txt +0 -0
- {linuxmonitor-1.2.2 → linuxmonitor-1.2.5}/README.md +0 -0
- {linuxmonitor-1.2.2 → linuxmonitor-1.2.5}/linuxmonitor/__init__.py +0 -0
- {linuxmonitor-1.2.2 → linuxmonitor-1.2.5}/linuxmonitor/__main__.py +0 -0
- {linuxmonitor-1.2.2 → linuxmonitor-1.2.5}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: LinuxMonitor
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.5
|
|
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.2.
|
|
3
|
+
Version: 1.2.5
|
|
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
|
|
@@ -30,7 +30,7 @@ __email__ = "quentin@comte-gaz.com"
|
|
|
30
30
|
__license__ = "MIT License"
|
|
31
31
|
__copyright__ = "Copyright Quentin Comte-Gaz (2024)"
|
|
32
32
|
__python_version__ = "3.+"
|
|
33
|
-
__version__ = "1.2.
|
|
33
|
+
__version__ = "1.2.5 (2024/09/16)"
|
|
34
34
|
__status__ = "Usable for any Linux project"
|
|
35
35
|
|
|
36
36
|
import json
|
|
@@ -179,7 +179,7 @@ class LinuxMonitor:
|
|
|
179
179
|
|
|
180
180
|
#region Execute Command
|
|
181
181
|
|
|
182
|
-
async def execute_and_verify(self, command: List[str], display_name: str, timeout_in_sec: Optional[int] = None, display_only_if_critical: bool = False, check_also_stdout_not_containing: Optional[str] = None) -> Tuple[Optional[bool], str]:
|
|
182
|
+
async def execute_and_verify(self, command: List[str], display_name: str, show_only_std_and_exception: bool, timeout_in_sec: Optional[int] = None, display_only_if_critical: bool = False, check_also_stdout_not_containing: Optional[str] = None) -> Tuple[Optional[bool], str]:
|
|
183
183
|
"""
|
|
184
184
|
Execute a shell command asynchronously and verify its correct execution.
|
|
185
185
|
|
|
@@ -211,7 +211,10 @@ class LinuxMonitor:
|
|
|
211
211
|
return None, f"⚠️ **Error {display_name}**:\n- Failed to execute the command in less than {timeout_in_sec} seconds)"
|
|
212
212
|
except Exception as e:
|
|
213
213
|
# Failed to execute the command
|
|
214
|
-
|
|
214
|
+
if not show_only_std_and_exception:
|
|
215
|
+
out_msg = f"⚠️ **Error {display_name}**:\n```sh\n{e}\n```"
|
|
216
|
+
else:
|
|
217
|
+
out_msg = f"```sh\n{e}\n```"
|
|
215
218
|
logging.exception(msg=out_msg)
|
|
216
219
|
return None, out_msg
|
|
217
220
|
|
|
@@ -227,22 +230,25 @@ class LinuxMonitor:
|
|
|
227
230
|
out_msg: str = ""
|
|
228
231
|
if res == False:
|
|
229
232
|
# Command returned an error code
|
|
230
|
-
|
|
233
|
+
if not show_only_std_and_exception:
|
|
234
|
+
out_msg = f"❌ **Error {display_name}**\n"
|
|
231
235
|
out_msg += f"- Error code: {returncode}"
|
|
232
236
|
|
|
233
237
|
if stderr_str != "":
|
|
234
|
-
out_msg += f"- Error log:\n```sh\n{stderr_str}\n```"
|
|
238
|
+
out_msg += f"\n- Error log:\n```sh\n{stderr_str}\n```"
|
|
235
239
|
|
|
236
240
|
if stdout_str != "":
|
|
237
|
-
out_msg += f"- Info:\n```sh\n{stdout_str}\n```"
|
|
241
|
+
out_msg += f"\n- Info:\n```sh\n{stdout_str}\n```"
|
|
238
242
|
elif res == None:
|
|
239
243
|
# Command timed out
|
|
240
|
-
|
|
244
|
+
if not show_only_std_and_exception:
|
|
245
|
+
out_msg = f"⚠️ **Error {display_name}**\n"
|
|
241
246
|
out_msg += f"- Failed to wait for the command to finish (due to timeout of {timeout_in_sec} seconds)"
|
|
242
247
|
else:
|
|
243
248
|
# Command executed successfully
|
|
244
249
|
if not display_only_if_critical:
|
|
245
|
-
|
|
250
|
+
if not show_only_std_and_exception:
|
|
251
|
+
out_msg = f"✅ **{display_name} executed successfully**"
|
|
246
252
|
|
|
247
253
|
if res == True:
|
|
248
254
|
logging.info(msg=f"Command {display_name} (command {command}) executed successfully")
|
|
@@ -264,7 +270,7 @@ class LinuxMonitor:
|
|
|
264
270
|
IMPORTANT: To be usable, the user must have the right to execute `sudo /sbin/reboot` command without password.
|
|
265
271
|
"""
|
|
266
272
|
logging.info(msg="Rebooting the server...")
|
|
267
|
-
_, out_msg = await self.execute_and_verify(command=["sudo", "/sbin/reboot"], display_name="Server reboot", timeout_in_sec=None, display_only_if_critical=False)
|
|
273
|
+
_, out_msg = await self.execute_and_verify(command=["sudo", "/sbin/reboot"], display_name="Server reboot", show_only_std_and_exception=False, timeout_in_sec=None, display_only_if_critical=False)
|
|
268
274
|
return out_msg
|
|
269
275
|
|
|
270
276
|
#endregion
|
|
@@ -747,7 +753,7 @@ class LinuxMonitor:
|
|
|
747
753
|
display_name = f"[{display_name}](https://{website})"
|
|
748
754
|
|
|
749
755
|
start_time: float = time.time()
|
|
750
|
-
res, out_msg = await self.execute_and_verify(command=ping_command, display_name=f"ping {display_name}", timeout_in_sec=timeout_in_sec, display_only_if_critical=display_only_if_critical)
|
|
756
|
+
res, out_msg = await self.execute_and_verify(command=ping_command, display_name=f"ping {display_name}", show_only_std_and_exception=False, timeout_in_sec=timeout_in_sec, display_only_if_critical=display_only_if_critical)
|
|
751
757
|
end_time: float = time.time()
|
|
752
758
|
|
|
753
759
|
if res == True and not display_only_if_critical:
|
|
@@ -938,13 +944,18 @@ class LinuxMonitor:
|
|
|
938
944
|
logging.info(f"Trying to restart {display_name} (command: {service_call}) in less than {timeout_in_sec}sec...")
|
|
939
945
|
|
|
940
946
|
start_time: float = time.time()
|
|
941
|
-
res,
|
|
947
|
+
res, res_msg = await self.execute_and_verify(command=service_call, display_name=f"restart {display_name}", show_only_std_and_exception=True, timeout_in_sec=timeout_in_sec, display_only_if_critical=False)
|
|
942
948
|
end_time: float = time.time()
|
|
943
949
|
|
|
944
950
|
if res == True:
|
|
945
951
|
readable_duration: str = "{:.2f}".format(end_time - start_time)
|
|
946
952
|
out_msg = f"✅ **{display_name} restarted with success** in {readable_duration}sec."
|
|
947
953
|
logging.info(msg=out_msg)
|
|
954
|
+
else:
|
|
955
|
+
out_msg = f"❌ **Error restarting service {display_name}**"
|
|
956
|
+
if res_msg and res_msg != "":
|
|
957
|
+
out_msg += f"\n{res_msg}"
|
|
958
|
+
logging.warning(msg=out_msg)
|
|
948
959
|
|
|
949
960
|
return out_msg
|
|
950
961
|
except Exception as e:
|
|
@@ -1004,7 +1015,7 @@ class LinuxMonitor:
|
|
|
1004
1015
|
status_command = service['status_command']
|
|
1005
1016
|
check_also_stdout_not_containing = service.get('check_also_stdout_not_containing', None)
|
|
1006
1017
|
|
|
1007
|
-
res, out_msg = await self.execute_and_verify(command=status_command, display_name=f"état de {display_name}", timeout_in_sec=timeout_in_sec, display_only_if_critical=False, check_also_stdout_not_containing=check_also_stdout_not_containing)
|
|
1018
|
+
res, out_msg = await self.execute_and_verify(command=status_command, display_name=f"état de {display_name}", show_only_std_and_exception=True, timeout_in_sec=timeout_in_sec, display_only_if_critical=False, check_also_stdout_not_containing=check_also_stdout_not_containing)
|
|
1008
1019
|
return res, out_msg
|
|
1009
1020
|
except Exception as e:
|
|
1010
1021
|
out_msg = f"⚠️ **Error checking status of service {service_name}**:\n```sh\n{e}\n```"
|
|
@@ -1065,10 +1076,11 @@ class LinuxMonitor:
|
|
|
1065
1076
|
out_msg_full: str = ""
|
|
1066
1077
|
try:
|
|
1067
1078
|
for service_name in self.config["services"].keys():
|
|
1079
|
+
out_msg: str = ""
|
|
1068
1080
|
if is_private or self.config["services"][service_name]['is_private'] == is_private:
|
|
1069
1081
|
status, status_msg = await self._get_service_status(is_private=is_private, service_name=service_name)
|
|
1070
1082
|
if status is False:
|
|
1071
|
-
out_msg
|
|
1083
|
+
out_msg = f"❌ **{self.config['services'][service_name]['display_name']} inactive**. Restarting the service is necessary."
|
|
1072
1084
|
logging.warning(msg=out_msg)
|
|
1073
1085
|
if status_msg != "":
|
|
1074
1086
|
out_msg += f"\n{status_msg}"
|
|
@@ -1644,7 +1656,7 @@ class LinuxMonitor:
|
|
|
1644
1656
|
|
|
1645
1657
|
# Attempt to terminate the process
|
|
1646
1658
|
terminate_command: List[str] = ['sudo', '/bin/kill', '-TERM', str(pid)]
|
|
1647
|
-
result_terminate, _ = await self.execute_and_verify(command=terminate_command, display_name=f"stop process {pid} ({process_name})", timeout_in_sec=timeout_in_sec, display_only_if_critical=False)
|
|
1659
|
+
result_terminate, _ = await self.execute_and_verify(command=terminate_command, display_name=f"stop process {pid} ({process_name})", show_only_std_and_exception=False, timeout_in_sec=timeout_in_sec, display_only_if_critical=False)
|
|
1648
1660
|
|
|
1649
1661
|
if result_terminate == True:
|
|
1650
1662
|
out_msg = f"✅ **Process {pid} ({process_name}) stopped with success** (nicely)).\n"
|
|
@@ -1656,7 +1668,7 @@ class LinuxMonitor:
|
|
|
1656
1668
|
|
|
1657
1669
|
# Attempt to kill the process
|
|
1658
1670
|
kill_command = ['sudo', '/bin/kill', '-KILL', str(pid)]
|
|
1659
|
-
_, strerror_kill = await self.execute_and_verify(command=kill_command, display_name=f"kill process {pid} ({process_name})", timeout_in_sec=timeout_in_sec, display_only_if_critical=False)
|
|
1671
|
+
_, strerror_kill = await self.execute_and_verify(command=kill_command, display_name=f"kill process {pid} ({process_name})", show_only_std_and_exception=True, timeout_in_sec=timeout_in_sec, display_only_if_critical=False)
|
|
1660
1672
|
out_msg += strerror_kill
|
|
1661
1673
|
|
|
1662
1674
|
if process_cpu_percent > 0:
|
|
@@ -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.2.
|
|
9
|
+
version="1.2.5",
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|