Create HTTP-GET alert via python-gvm

Hi,

can someone give me an example of calling create_alert() function, with method=HTTP_GET. I am in trouble with method_data parameter, how can I correctly use if to specify URL for GET request.

Firstly I tried to use a dict such this {"http_get_url": "127.0.0.1:9999"}, but it didn’t work.

I tried to create alert via web UI, then looked in postgres base, and checked alert_method_data table, for this alert there was something more, then just http_get_url, and i tried dict like

{
    "delta_type": "None",
    "http_get_url": "127.0.0.1:9999",
    "delta_report_id": "",
    "details_url": "https://secinfo.greenbone.net/omp?cmd=get_info&info_type=$t&info_id=$o&details=1&token=guest"
}

but, unfortunately, it didn’t work too. After this I checked API docs and python-gvm docs, and didn’t find there an answer.

So, can someone please give me correct example how to call create_alert() function in such way.

Used python-gvm version 1.6.0, with GMP connection.

Apologize if I used wrong category, and for my english :slight_smile:

Thank you!

Hi,

So I just ran into the same use-case, I solved it by first creating one manually in GSA, then using the get_alert method to see how it’s called:

This worked for me on 20.08:

resp = gmp.create_alert(
    name="api_alert_done",
    condition=AlertCondition.ALWAYS,
    event=AlertEvent.TASK_RUN_STATUS_CHANGED,
    event_data={"status": "Done"},
    method=AlertMethod.HTTP_GET,
    method_data={
        "URL": "https://example.com/alert?taskname=$n".format(env)
    }
)

It appears it’s case sensative.

3 Likes

Thank you a lot, it works for me too!