forta-network / forta-bot-sdk

Forta Detection Bot SDK and CLI tool
MIT License
71 stars 38 forks source link

python external bot support #347

Closed haseebrabbani closed 1 year ago

haseebrabbani commented 1 year ago

first need to set FORTA_API_KEY env variable. example usage:

response = send_alerts([{
    "bot_id": "0x42265c815a3f2cc137bcd30f6688860ac0201911ce6006576b4b3e7f6e62ddc6",
    "finding": Finding({
        "name": f'haseeb python test {datetime.now()}',
        "description": "this is a python test",
        "alert_id": "HASEEB_PY_TEST_1",
        "type": FindingType.Exploit,
        "severity": FindingSeverity.Info,
        "labels": [
            Label({
              "entityType": EntityType.Address,
              "entity": "0x87fb424282bd043de413aa74153af073d8c9bbb5",
              "confidence": 0.95,
              "label": "Attackerrr",
              "metadata": {
                  "some": "data",
              },
            }),
            Label({
                "entityType": EntityType.Unknown,
                "entity": "bla",
                "confidence": 0.15,
                "label": "Hacker",
            }),
        ],
        "source": {
            "chains": [
                {
                    "chainId": 137,
                },
            ],
            "transactions": [
                {
                    'chainId': 137,
                    'hash': "0xcc8dedfbc2c2757e793ccc781746a8996658541885017314ced5138ae6009f26",
                },
                {
                    'chainId': 1,
                    'hash': "0x0ce941aae4eecdd1cae0fe4c90e8c3b14a84f346b669c60e654b2eecd736b9b6",
                },
            ],
        },
        "addresses": ["0x87fb424282bd043de413aa74153af073d8c9bbb5"],
        "metadata": {
            "chain": "137",
        },
        "uniqueKey": f'HASEEB-{datetime.now().timestamp()}',
        "timestamp": datetime.fromtimestamp(1694214981)
    })
}, {
    "bot_id":  "0x075384e577be5c17efdc6cec5e80b3f84fb5b40257d8ecdd8ab0a542f8a6e084",
    "finding": Finding({
        "name": f'haseeb python test {datetime.now()}',
        "description": "this is a python test",
        "alert_id": "HASEEB_PY_TEST_1",
        "type": FindingType.Exploit,
        "severity": FindingSeverity.Info
    })
}
])
print(response)