LinuxMonitor 1.2.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: LinuxMonitor
3
- Version: 1.2.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.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.2 (2024/09/16)"
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
- out_msg = f"⚠️ **Error {display_name}**:\n```sh\n{e}\n```"
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
- out_msg = f"❌ **Error {display_name}**\n"
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
- out_msg = f"⚠️ **Error {display_name}**\n"
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
- out_msg = f"✅ **{display_name} executed successfully**"
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,7 +944,7 @@ 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, 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)
942
948
  end_time: float = time.time()
943
949
 
944
950
  if res == True:
@@ -1004,7 +1010,7 @@ class LinuxMonitor:
1004
1010
  status_command = service['status_command']
1005
1011
  check_also_stdout_not_containing = service.get('check_also_stdout_not_containing', None)
1006
1012
 
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)
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)
1008
1014
  return res, out_msg
1009
1015
  except Exception as e:
1010
1016
  out_msg = f"⚠️ **Error checking status of service {service_name}**:\n```sh\n{e}\n```"
@@ -1644,7 +1650,7 @@ class LinuxMonitor:
1644
1650
 
1645
1651
  # Attempt to terminate the process
1646
1652
  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)
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)
1648
1654
 
1649
1655
  if result_terminate == True:
1650
1656
  out_msg = f"✅ **Process {pid} ({process_name}) stopped with success** (nicely)).\n"
@@ -1656,7 +1662,7 @@ class LinuxMonitor:
1656
1662
 
1657
1663
  # Attempt to kill the process
1658
1664
  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)
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)
1660
1666
  out_msg += strerror_kill
1661
1667
 
1662
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.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