pyfortianalyzer


Namepyfortianalyzer JSON
Version 2.0.0 PyPI version JSON
download
home_pagehttps://github.com/BESTSELLER/pyfortianalyzer
SummaryPython API client library for Fortinet's FortiAnalyzer.
upload_time2024-02-23 07:08:21
maintainer
docs_urlNone
authorRasmus Thing
requires_python>=3.8, <4
licenseApache2
keywords fortinet fortianalyzer
VCS
bugtrack_url
requirements requests
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyfortianalyzer
Python API client library for Fortinet's [FortiAnalyzer](https://www.fortinet.com/products/management/fortianalyzer).

It does not provide all endpoints or functionality available. We encourage to make a pull request with needed missing endpoints.

> **Note:** This library has been built and tested for FortiAnalyzer v7.2.x.

## Installation
To install run `pip install pyfortianalyzer`.

Alternatively, you can clone the repo and run `python setup.py install`.

## Quick Start
To begin, import pyfortianalyzer and instantiate the API.

We need to provide the IP or FQDN to the FortiAnalyzer instance and a user with access to the API.
Optionally, its possible to set `adom` which defaults to `root` and `verify` which defaults to `True`.

**Code**
```
import pyfortianalyzer
fortianalyzer = pyfortianalyzer.api(
    host = "https://fortianalyzer.example.com",
    token = "<api_token_from_faz>"
)
```

## Examples
### List all FortiGates.
There is a ton of data for a single FortiGate. This code retrieves all of it, but only prints the name of the FortiGates.

**Code**
```
faz_fortigates = fortianalyzer.fortigates.all()
for faz_fortigate in faz_fortigates['data']:
    print(faz_fortigate['name'])
```

**Output**
```
FortiGate-VM64-1
FortiGate-VM64-2
FortiGate-VM64-3
```

### Status object.
You can use the status object to check if the request is a success or not, and retrieve the error message.

**Code**
```
faz_fortigate = fortianalyzer.fortigates.all(fortigate="FortiGate-VM64-4")
if faz_fortigate['status']['code'] == 0:
    print(faz_fortigate['data']['name'])
else:
    print(faz_fortigate['status'])
```

**Output**
```
"status": {
    "code": -3,
    "message": "Object does not exist"
}
```


### Custom API request.
Since FortiAnalyzer consists of a ton of API endpoints, not all are supported natively in this module.

You can however use the custom_request function in order to reach any API endpoint in FortiAnalyzer.

**Code**
```
faz_custom_request = FortiAnalyzer.system.custom_request(
    params={
        "url": "/dvmdb/adom/root/device",
        "option": [
            "get meta"
        ]
    },
    method="get"
)
print(json.dumps(faz_custom_request, indent=4))
```

### Adding a FortiGate
This adds a FortiGate in the Device Manager with the minimum required fields.

**Code**
```
faz_fortigate_add = fortianalyzer.fortigates.add(
    serial = "FGT60FTK1234ABCD"
)
print(faz_fortigate_add)
```

**Output**
```
{
    "data": {
        "device": {
            "beta": -1,
            "conn_mode": 1,
            "dev_status": 1,
            "flags": 67371008,
            "hostname": "FGT60FTK1234ABCD",
            "maxvdom": 10,
            "mgmt_id": 965165689,
            "mgmt_mode": 2,
            "mr": -1,
            "name": "FGT60FTK1234ABCD",
            "oid": 3999,
            "os_type": 0,
            "os_ver": -1,
            "patch": -1,
            "platform_id": 19,
            "platform_str": "FortiGate-60F",
            "sn": "FGT60FTK1234ABCD",
            "source": 1,
            "tab_status": "<unknown>"
        }
    },
    "status": {
        "code": 0,
        "message": "OK"
    },
    "url": "/dvm/cmd/add/device"
}
```

### Updating a FortiGate
This updates a FortiGate in the Device Manager.

**Code**
```
faz_fortigate_update = fortianalyzer.fortigates.update(
    fortigate = "FortiGate-VM64-1",
    description = "Test FortiGate"
)
print(faz_fortigate_update)
```

**Output**
```
{
    "data": {
        "name": "FortiGate-VM64-1"
    },
    "status": {
        "code": 0,
        "message": "OK"
    },
    "url": "/dvmdb/adom/root/device/FortiGate-VM64-1"
}
```

### Deleting a FortiGate
This deletes a FortiGate in the Device Manager.

**Code**
```
faz_fortigate_delete = fortianalyzer.fortigates.delete(
    fortigate = "FortiGate-VM64-1"
)
print(faz_fortigate_delete)
```

**Output**
```
{
    "status": {
        "code": 0,
        "message": "OK"
    },
    "url": "/dvm/cmd/del/device"
}
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/BESTSELLER/pyfortianalyzer",
    "name": "pyfortianalyzer",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8, <4",
    "maintainer_email": "",
    "keywords": "fortinet,fortianalyzer",
    "author": "Rasmus Thing",
    "author_email": "rasmus.thing@bestseller.com",
    "download_url": "https://files.pythonhosted.org/packages/45/fe/7e142663595e330074106f4b4d0cf076cef8adc06968d773396786d4c8c2/pyfortianalyzer-2.0.0.tar.gz",
    "platform": null,
    "description": "# pyfortianalyzer\nPython API client library for Fortinet's [FortiAnalyzer](https://www.fortinet.com/products/management/fortianalyzer).\n\nIt does not provide all endpoints or functionality available. We encourage to make a pull request with needed missing endpoints.\n\n> **Note:** This library has been built and tested for FortiAnalyzer v7.2.x.\n\n## Installation\nTo install run `pip install pyfortianalyzer`.\n\nAlternatively, you can clone the repo and run `python setup.py install`.\n\n## Quick Start\nTo begin, import pyfortianalyzer and instantiate the API.\n\nWe need to provide the IP or FQDN to the FortiAnalyzer instance and a user with access to the API.\nOptionally, its possible to set `adom` which defaults to `root` and `verify` which defaults to `True`.\n\n**Code**\n```\nimport pyfortianalyzer\nfortianalyzer = pyfortianalyzer.api(\n    host = \"https://fortianalyzer.example.com\",\n    token = \"<api_token_from_faz>\"\n)\n```\n\n## Examples\n### List all FortiGates.\nThere is a ton of data for a single FortiGate. This code retrieves all of it, but only prints the name of the FortiGates.\n\n**Code**\n```\nfaz_fortigates = fortianalyzer.fortigates.all()\nfor faz_fortigate in faz_fortigates['data']:\n    print(faz_fortigate['name'])\n```\n\n**Output**\n```\nFortiGate-VM64-1\nFortiGate-VM64-2\nFortiGate-VM64-3\n```\n\n### Status object.\nYou can use the status object to check if the request is a success or not, and retrieve the error message.\n\n**Code**\n```\nfaz_fortigate = fortianalyzer.fortigates.all(fortigate=\"FortiGate-VM64-4\")\nif faz_fortigate['status']['code'] == 0:\n    print(faz_fortigate['data']['name'])\nelse:\n    print(faz_fortigate['status'])\n```\n\n**Output**\n```\n\"status\": {\n    \"code\": -3,\n    \"message\": \"Object does not exist\"\n}\n```\n\n\n### Custom API request.\nSince FortiAnalyzer consists of a ton of API endpoints, not all are supported natively in this module.\n\nYou can however use the custom_request function in order to reach any API endpoint in FortiAnalyzer.\n\n**Code**\n```\nfaz_custom_request = FortiAnalyzer.system.custom_request(\n    params={\n        \"url\": \"/dvmdb/adom/root/device\",\n        \"option\": [\n            \"get meta\"\n        ]\n    },\n    method=\"get\"\n)\nprint(json.dumps(faz_custom_request, indent=4))\n```\n\n### Adding a FortiGate\nThis adds a FortiGate in the Device Manager with the minimum required fields.\n\n**Code**\n```\nfaz_fortigate_add = fortianalyzer.fortigates.add(\n    serial = \"FGT60FTK1234ABCD\"\n)\nprint(faz_fortigate_add)\n```\n\n**Output**\n```\n{\n    \"data\": {\n        \"device\": {\n            \"beta\": -1,\n            \"conn_mode\": 1,\n            \"dev_status\": 1,\n            \"flags\": 67371008,\n            \"hostname\": \"FGT60FTK1234ABCD\",\n            \"maxvdom\": 10,\n            \"mgmt_id\": 965165689,\n            \"mgmt_mode\": 2,\n            \"mr\": -1,\n            \"name\": \"FGT60FTK1234ABCD\",\n            \"oid\": 3999,\n            \"os_type\": 0,\n            \"os_ver\": -1,\n            \"patch\": -1,\n            \"platform_id\": 19,\n            \"platform_str\": \"FortiGate-60F\",\n            \"sn\": \"FGT60FTK1234ABCD\",\n            \"source\": 1,\n            \"tab_status\": \"<unknown>\"\n        }\n    },\n    \"status\": {\n        \"code\": 0,\n        \"message\": \"OK\"\n    },\n    \"url\": \"/dvm/cmd/add/device\"\n}\n```\n\n### Updating a FortiGate\nThis updates a FortiGate in the Device Manager.\n\n**Code**\n```\nfaz_fortigate_update = fortianalyzer.fortigates.update(\n    fortigate = \"FortiGate-VM64-1\",\n    description = \"Test FortiGate\"\n)\nprint(faz_fortigate_update)\n```\n\n**Output**\n```\n{\n    \"data\": {\n        \"name\": \"FortiGate-VM64-1\"\n    },\n    \"status\": {\n        \"code\": 0,\n        \"message\": \"OK\"\n    },\n    \"url\": \"/dvmdb/adom/root/device/FortiGate-VM64-1\"\n}\n```\n\n### Deleting a FortiGate\nThis deletes a FortiGate in the Device Manager.\n\n**Code**\n```\nfaz_fortigate_delete = fortianalyzer.fortigates.delete(\n    fortigate = \"FortiGate-VM64-1\"\n)\nprint(faz_fortigate_delete)\n```\n\n**Output**\n```\n{\n    \"status\": {\n        \"code\": 0,\n        \"message\": \"OK\"\n    },\n    \"url\": \"/dvm/cmd/del/device\"\n}\n```\n",
    "bugtrack_url": null,
    "license": "Apache2",
    "summary": "Python API client library for Fortinet's FortiAnalyzer.",
    "version": "2.0.0",
    "project_urls": {
        "Homepage": "https://github.com/BESTSELLER/pyfortianalyzer"
    },
    "split_keywords": [
        "fortinet",
        "fortianalyzer"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7f6397c116dd04b7a11a60898d468570fad4c42fe898e9874bc7607449bdd76e",
                "md5": "8630ebbc124bb7f6601f545440709dd3",
                "sha256": "7b72fe9340c538dec7cd0a9ce0a5bba43ede029af9f93e30cafd07d1f982b856"
            },
            "downloads": -1,
            "filename": "pyfortianalyzer-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8630ebbc124bb7f6601f545440709dd3",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8, <4",
            "size": 10807,
            "upload_time": "2024-02-23T07:08:19",
            "upload_time_iso_8601": "2024-02-23T07:08:19.238542Z",
            "url": "https://files.pythonhosted.org/packages/7f/63/97c116dd04b7a11a60898d468570fad4c42fe898e9874bc7607449bdd76e/pyfortianalyzer-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "45fe7e142663595e330074106f4b4d0cf076cef8adc06968d773396786d4c8c2",
                "md5": "b1d25d745d896f7fe5c194ffafa753ed",
                "sha256": "6c00e03e193b5eef515807bce10d7e85866c2baa4b191f7a4e5f88162e496477"
            },
            "downloads": -1,
            "filename": "pyfortianalyzer-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b1d25d745d896f7fe5c194ffafa753ed",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8, <4",
            "size": 10353,
            "upload_time": "2024-02-23T07:08:21",
            "upload_time_iso_8601": "2024-02-23T07:08:21.002228Z",
            "url": "https://files.pythonhosted.org/packages/45/fe/7e142663595e330074106f4b4d0cf076cef8adc06968d773396786d4c8c2/pyfortianalyzer-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-23 07:08:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "BESTSELLER",
    "github_project": "pyfortianalyzer",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "requests",
            "specs": [
                [
                    "<",
                    "3.0"
                ],
                [
                    ">=",
                    "2.20.0"
                ]
            ]
        }
    ],
    "lcname": "pyfortianalyzer"
}
        
Elapsed time: 0.19058s