Forum Discussion

DanBuck's avatar
DanBuck
Icon for Contributor rankContributor
23 days ago
Solved

Elevated Privileges for Python3 Libraries

We are stuck trying to recreate some of the metrics we collect in our current Python2 snippets using pipes.

The specific example is 'ping', which required subprocesses, no longer allowed. We don't believe  latency_ping,avail_ping from silo_tools will let us collect packet_count, packet_loss, avg_latencies, latencies that a library like ping3 allows. (used to calculate jitter and else)

Some of the libraries seem to require raw sockets and/or elevated privileges. So our question is two fold.

1 - Can we import custom libraries such as Ping3?

2 - How do we use elevated privileges on the collectors, as some libraries require elevated priveleges?

Thanks in advance, Dan

  • Dan,

    I can address the first question. You should be able to pull in that ping3 wheel/library using these instructions: https://docs.sciencelogic.com/latest/Content/Web_Content_Dev_and_Integration/ScienceLogic_Libraries/chapter_02_managing_libraries.htm?Highlight=science%20logic%20library#manually-building-a-sciencelogic-library

    That library is fairly simple to pull in because it doesn't require to be compiled and it has no other dependent libraries or wheels. The instructions should boil down:

    • Saving that wheel from pypi
    • Creating a metadata.json file describing the library and the wheels is contained in the SL library (see below)
    • Creating a tar file that contains the wheel(s) and the metadata.json file.

    Your metadata.json should look like this...

    {
        "meta_version": "0.2",
        "fields": {
            "description": "Ping3 Library",
            "manifest": [
                "ping3-4.0.8-py3-none-any.whl"
            ],
            "name": "ping3",
            "type": "py_package",
            "version": "4.0.8",
            "requires_python": ">=3.5"
        }
    }

    From there you should be able to import and align the SL library into your SL1.

    Your tar file listing should look like this...

    [workspace]# tar tvf ping3+4.0.8.py36.tar
    -rw-r--r-- root/root       287 2024-06-20 13:35 metadata.json
    -rw-r--r-- root/root     14007 2024-06-20 13:33 ping3-4.0.8-py3-none-any.whl

    Some gotchas is that you need to prepare the SL library on an OracleLinux or RedHat variant.

    Hope that helps and let me know how it goes!

     

11 Replies

  • Dan,

    I can address the first question. You should be able to pull in that ping3 wheel/library using these instructions: https://docs.sciencelogic.com/latest/Content/Web_Content_Dev_and_Integration/ScienceLogic_Libraries/chapter_02_managing_libraries.htm?Highlight=science%20logic%20library#manually-building-a-sciencelogic-library

    That library is fairly simple to pull in because it doesn't require to be compiled and it has no other dependent libraries or wheels. The instructions should boil down:

    • Saving that wheel from pypi
    • Creating a metadata.json file describing the library and the wheels is contained in the SL library (see below)
    • Creating a tar file that contains the wheel(s) and the metadata.json file.

    Your metadata.json should look like this...

    {
        "meta_version": "0.2",
        "fields": {
            "description": "Ping3 Library",
            "manifest": [
                "ping3-4.0.8-py3-none-any.whl"
            ],
            "name": "ping3",
            "type": "py_package",
            "version": "4.0.8",
            "requires_python": ">=3.5"
        }
    }

    From there you should be able to import and align the SL library into your SL1.

    Your tar file listing should look like this...

    [workspace]# tar tvf ping3+4.0.8.py36.tar
    -rw-r--r-- root/root       287 2024-06-20 13:35 metadata.json
    -rw-r--r-- root/root     14007 2024-06-20 13:33 ping3-4.0.8-py3-none-any.whl

    Some gotchas is that you need to prepare the SL library on an OracleLinux or RedHat variant.

    Hope that helps and let me know how it goes!

     

    • DanBuck's avatar
      DanBuck
      Icon for Contributor rankContributor

      That does help, we will give that a shot. TY!

      • Ishanc's avatar
        Ishanc
        Icon for Contributor rankContributor

        I tried, it's the same permission problem. Needs elevated permission to create sockets since ping3 uses that.

        Error encountered while executing snippet. Error explanation: App: 2025, Snippet: 2384 threw exception: [Errno 13] Permission denied (PermissionError: [Errno 13] Permission denied _socket.socket.__init__(self, family, type, proto, fileno))