LinuxMonitor 1.2.1__tar.gz → 1.2.4__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.1 → linuxmonitor-1.2.4/LinuxMonitor.egg-info}/PKG-INFO +1 -1
- {linuxmonitor-1.2.1/LinuxMonitor.egg-info → linuxmonitor-1.2.4}/PKG-INFO +1 -1
- {linuxmonitor-1.2.1 → linuxmonitor-1.2.4}/linuxmonitor/linuxmonitor.py +26 -17
- {linuxmonitor-1.2.1 → linuxmonitor-1.2.4}/setup.py +1 -1
- {linuxmonitor-1.2.1 → linuxmonitor-1.2.4}/LICENSE.md +0 -0
- {linuxmonitor-1.2.1 → linuxmonitor-1.2.4}/LinuxMonitor.egg-info/SOURCES.txt +0 -0
- {linuxmonitor-1.2.1 → linuxmonitor-1.2.4}/LinuxMonitor.egg-info/dependency_links.txt +0 -0
- {linuxmonitor-1.2.1 → linuxmonitor-1.2.4}/LinuxMonitor.egg-info/requires.txt +0 -0
- {linuxmonitor-1.2.1 → linuxmonitor-1.2.4}/LinuxMonitor.egg-info/top_level.txt +0 -0
- {linuxmonitor-1.2.1 → linuxmonitor-1.2.4}/README.md +0 -0
- {linuxmonitor-1.2.1 → linuxmonitor-1.2.4}/linuxmonitor/__init__.py +0 -0
- {linuxmonitor-1.2.1 → linuxmonitor-1.2.4}/linuxmonitor/__main__.py +0 -0
- {linuxmonitor-1.2.1 → linuxmonitor-1.2.4}/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.4
|
|
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.4
|
|
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.3 (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:
|
|
@@ -818,9 +824,12 @@ class LinuxMonitor:
|
|
|
818
824
|
|
|
819
825
|
# Check if the status code is within the allowed list
|
|
820
826
|
if response.status in allowed_statuses:
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
827
|
+
if not display_only_if_critical:
|
|
828
|
+
out_msg: str = f"✅ **{display_name} answered with valid status code {response.status}** in {end_time - start_time:.2f}sec."
|
|
829
|
+
logging.info(msg=out_msg)
|
|
830
|
+
return True, out_msg
|
|
831
|
+
else:
|
|
832
|
+
return True, ""
|
|
824
833
|
else:
|
|
825
834
|
# Get the reason phrase (e.g., "Unauthorized" for 401)
|
|
826
835
|
status_reason: str = responses.get(response.status, "Unknown status")
|
|
@@ -935,7 +944,7 @@ class LinuxMonitor:
|
|
|
935
944
|
logging.info(f"Trying to restart {display_name} (command: {service_call}) in less than {timeout_in_sec}sec...")
|
|
936
945
|
|
|
937
946
|
start_time: float = time.time()
|
|
938
|
-
res, out_msg = await self.execute_and_verify(command=service_call, display_name=f"restart {display_name}", timeout_in_sec=timeout_in_sec, display_only_if_critical=False)
|
|
947
|
+
res, out_msg = await self.execute_and_verify(command=service_call, display_name=f"restart {display_name}", show_only_std_and_exception=False, timeout_in_sec=timeout_in_sec, display_only_if_critical=False)
|
|
939
948
|
end_time: float = time.time()
|
|
940
949
|
|
|
941
950
|
if res == True:
|
|
@@ -1001,7 +1010,7 @@ class LinuxMonitor:
|
|
|
1001
1010
|
status_command = service['status_command']
|
|
1002
1011
|
check_also_stdout_not_containing = service.get('check_also_stdout_not_containing', None)
|
|
1003
1012
|
|
|
1004
|
-
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)
|
|
1013
|
+
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)
|
|
1005
1014
|
return res, out_msg
|
|
1006
1015
|
except Exception as e:
|
|
1007
1016
|
out_msg = f"⚠️ **Error checking status of service {service_name}**:\n```sh\n{e}\n```"
|
|
@@ -1641,7 +1650,7 @@ class LinuxMonitor:
|
|
|
1641
1650
|
|
|
1642
1651
|
# Attempt to terminate the process
|
|
1643
1652
|
terminate_command: List[str] = ['sudo', '/bin/kill', '-TERM', str(pid)]
|
|
1644
|
-
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)
|
|
1653
|
+
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)
|
|
1645
1654
|
|
|
1646
1655
|
if result_terminate == True:
|
|
1647
1656
|
out_msg = f"✅ **Process {pid} ({process_name}) stopped with success** (nicely)).\n"
|
|
@@ -1653,7 +1662,7 @@ class LinuxMonitor:
|
|
|
1653
1662
|
|
|
1654
1663
|
# Attempt to kill the process
|
|
1655
1664
|
kill_command = ['sudo', '/bin/kill', '-KILL', str(pid)]
|
|
1656
|
-
_, 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)
|
|
1665
|
+
_, 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)
|
|
1657
1666
|
out_msg += strerror_kill
|
|
1658
1667
|
|
|
1659
1668
|
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.4",
|
|
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
|