Giter VIP home page Giter VIP logo

alertlogic-sdk-python's Introduction

The Alert Logic SDK For Python (almdrlib)

pypi python Build Status Docs

Alert Logic Software Development Kit for Python allows developers to integrate with Alert Logic MDR Services.

Quick Start

  1. Install the library:

    pip install alertlogic-sdk-python

  2. Set up configuration file (in e.g. ~/.alertlogic/config

    [default]
    access_key_id = YOUR_KEY
    secret_key = YOUR_SECRET
    

    To create and manage access keys, use the Alert Logic Console. For information on creating an access key, see https://docs.alertlogic.com/prepare/access-key-management.htm

    Optionally you can specify if you are working with integration deployment of Alert Logic MDR Services or production by specifying:

    global_endpoint=integration
    
    global_endpoint=production
    

    NOTE: If global_endpoint isn't present, SDK defaults to production.

  3. Test installation Launch python interpreter and then type:

    import almdrlib
    aims = almdrlib.client("aims")
    res = aims.get_account_details()
    print(f"{res.json()}")
    

Development

Getting Started

Prerequisites:

  1. Python v3.7 or newer

  2. virtualenv or virtualenvwrapper (We recommend virtualenvwrapper https://virtualenvwrapper.readthedocs.io/en/latest/ )

  3. To produce RESTful APIs documentation install redoc-cli and npx:

    npm install --save redoc-cli
    npm install --save npx
    

Setup your development environment and install required dependencies:

export WORKON_HOME=~/environments
mkdir -p $WORKON_HOME
source /usr/local/bin/virtualenvwrapper.sh
mkvirtualenv alsdk
git clone https://github.com/alertlogic/alertlogic-sdk-python
cd alertlogic-sdk-python
pip install -r requirements_dev.txt
pip install -e .

Using local services

  • Setup a local profile:
[aesolo]
access_key_id=skip
secret_key=skip
global_endpoint=map
endpoint_map_file=aesolo.json
  • Write an endpoint map (here, ~/.alertlogic/aesolo.json; endpoint_map_file can also be an absolute path):
{
  "aecontent" : "http://127.0.0.1:8810",
  "aefr" : "http://127.0.0.1:8808",
  "aepublish" : "http://127.0.0.1:8811",
  "aerta" : "http://127.0.0.1:8809",
  "aetag" : "http://127.0.0.1:8812",
  "aetuner": "http://127.0.0.1:3000",
  "ingest" : "http://127.0.0.1:9000"
}

Alternatively global_endpoint configuration option or ALERTLOGIC_ENDPOINT value might be set to the url value:

[aesolo]
access_key_id=skip
secret_key=skip
global_endpoint=http://api.aesolo.com
...
global_endpoint=http://api.aesolo.com:3001
export ALERTLOGIC_ENDPOINT="http://api.aesolo.com"
...
export ALERTLOGIC_ENDPOINT="http://api.aesolo.com:3001"

alertlogic-sdk-python's People

Contributors

anton-b avatar carlisom avatar daniel-zinov avatar dependabot[bot] avatar ebrown-al avatar hmartel avatar ivanu-at-al avatar james-bellamy avatar key-master avatar mcnielsen avatar mikebenza avatar motobob avatar msayler avatar pavel-puchkin avatar pixelpusherpitzer avatar ptrakhtman avatar raghavkarol avatar rmpalomino avatar sayler avatar va17 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alertlogic-sdk-python's Issues

endpoint lookup should happen on the account ID of the request

  • The Alert Logic SDK For Python version: almdrlib/1.0.50.dev0+gea8489c.d20201026
  • Python version: Python/3.8.6
  • Operating System: 20.3.0 Darwin

Description

When looking up an endpoint for a service call, this needs to happen based on the account ID in the request.

  • account_id in the parameters for a service call: use this ID for looking up the endpoint for the request
  • No account_id in the parameters, but account_id required by the API: account_id inherited from the logged in user, and used in endpoint lookup

Not sure what the behavior should be for services that don't have an account ID in the API definition (there are just a few of these)

Note: a single service client may make requests to many different account IDs over the course of its lifetime.

Update AL endpoint based on user account not working for testing use cases

Description

Updating the url based on customer residency does not work for test use cases. For example,

$ cat ~/.alertlogic/config

[aetuner_int]
access_key_id=skip
secret_key=skip
global_endpoint=localhost3001

$ cat api/aetuner.v1.yaml

...
servers:
  - url: 'https://aetuner.mdr.global.alertlogic.com'
    x-alertlogic-global-endpoint: production
    description: production
  - url: 'https://aetuner.mdr.product.dev.alertlogic.com'
    x-alertlogic-global-endpoint: integration
    description: integration
  - url: 'http://localhost:3000'
    x-alertlogic-global-endpoint: localhost3000
    description: localhost on port 3000
...

$  _venv/bin/alcli --profile aetuner_int aetuner get_analytic --account_id $account_id --path ngx/SuspConfCng/AwsPacu --enable_new=1

Traceback (most recent call last):
  File "/Users/rkarol-admin/github/alertlogic/aetuner/_venv/lib/python3.7/site-packages/alcli/alertlogic_cli.py", line 116, in main
    return services[parsed_args.service](remaining, parsed_args)
  File "/Users/rkarol-admin/github/alertlogic/aetuner/_venv/lib/python3.7/site-packages/alcli/alertlogic_cli.py", line 199, in __call__
    res = operation(**op_args)
  File "/Users/rkarol-admin/github/alertlogic/aetuner/_venv/lib/python3.7/site-packages/almdrlib/client.py", line 619, in __call__
    return self._call(*args, **kwargs)
  File "/Users/rkarol-admin/github/alertlogic/aetuner/_venv/lib/python3.7/site-packages/almdrlib/client.py", line 586, in f
    self._server.update_url(account_id)
  File "/Users/rkarol-admin/github/alertlogic/aetuner/_venv/lib/python3.7/site-packages/almdrlib/client.py", line 52, in update_url
    self._url = self._session.get_url(self._service_name, account_id)
  File "/Users/rkarol-admin/github/alertlogic/aetuner/_venv/lib/python3.7/site-packages/almdrlib/session.py", line 260, in get_url
    self.residency),
  File "/Users/rkarol-admin/github/alertlogic/aetuner/_venv/lib/python3.7/site-packages/almdrlib/session.py", line 304, in request
    **kwargs)
  File "/Users/rkarol-admin/github/alertlogic/aetuner/_venv/lib/python3.7/site-packages/requests/sessions.py", line 528, in request
    prep = self.prepare_request(req)
  File "/Users/rkarol-admin/github/alertlogic/aetuner/_venv/lib/python3.7/site-packages/requests/sessions.py", line 466, in prepare_request
    hooks=merge_hooks(request.hooks, self.hooks),
  File "/Users/rkarol-admin/github/alertlogic/aetuner/_venv/lib/python3.7/site-packages/requests/models.py", line 316, in prepare
    self.prepare_url(url, params)
  File "/Users/rkarol-admin/github/alertlogic/aetuner/_venv/lib/python3.7/site-packages/requests/models.py", line 390, in prepare_url
    raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL 'localhost3001/endpoints/v1/134255110/residency/default/services/aetuner/endpoint': No schema supplied. Perhaps you meant http://localhost3001/endpoints/v1/134255110/residency/default/services/aetuner/endpoint?

In these cases update_url here should not update the URL based on the customer residency.

No option to specify request timeout for almdrlib calls

  • The Alert Logic SDK For Python version: v1.0.71
  • Python version: 3.10
  • Operating System: macOS

Description

session.py does not specify a timeout parameter on calls to requests.session.request(). As a result, the well-documented default of the requests module is to apply no timeout. There is no way to override this behavior in almdrlib.

What I Did

Partial stack trace from a typical case where a request times out (here, because my machine went to sleep while a script was running)

  File "/Users/msayler/Projects/cli/alertlogic-sdk-python/almdrlib/client.py", line 709, in __call__
    return self._call(*args, **kwargs)
  File "/Users/msayler/Projects/cli/alertlogic-sdk-python/almdrlib/client.py", line 699, in f
    return self._session.request(
  File "/Users/msayler/Projects/cli/alertlogic-sdk-python/almdrlib/session.py", line 306, in request
    response = self._session.request(
  File "/opt/homebrew/lib/python3.10/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/opt/homebrew/lib/python3.10/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
  File "/opt/homebrew/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/opt/homebrew/lib/python3.10/site-packages/urllib3/connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/opt/homebrew/lib/python3.10/site-packages/urllib3/connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
  File "/opt/homebrew/Cellar/[email protected]/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 1374, in getresponse
    response.begin()
  File "/opt/homebrew/Cellar/[email protected]/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
  File "/opt/homebrew/Cellar/[email protected]/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/http/client.py", line 279, in _read_status
    line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
  File "/opt/homebrew/Cellar/[email protected]/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/socket.py", line 705, in readinto
    return self._sock.recv_into(b)
  File "/opt/homebrew/Cellar/[email protected]/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1274, in recv_into
    return self.read(nbytes, buffer)
  File "/opt/homebrew/Cellar/[email protected]/3.10.9/Frameworks/Python.framework/Versions/3.10/lib/python3.10/ssl.py", line 1130, in read
    return self._sslobj.read(len, buffer)
KeyboardInterrupt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.