Python script to run API call - AddWebsite - Need help with collectors
Hello,
I'm having troubles having a python script to work properly.
I manage to have my webcheck created. But it always comes with no collector/checkpoint.
Looking at the API sdk documentation doesn't really help me figure what I'm doing wrong.
I tried doing a GET on existing webchecks, to copy/paste the following blocks: test_location, Checkpoints, Collectors.
Here is a sample of my script:
(the collector name is: "domain\\servername")
I grabbed these blocks from the getwebsitelist output:
Here is the API output when I try to create the webcheck:
{'alert_expr': '',
'checkpoints': [{'geo_info': 'Overall', 'id': randomNumber, 'smg_id': 0}],
'collectors': [],
'description': 'Test API by Damien',
'disable_alerting': True,
'domain': 'Valid_website_url',
'global_sm_alert_cond': 0,
'group_id': 321,
'id': 4701,
'ignore_ssl': True,
'individual_alert_level': 'warn',
'individual_sm_alert_enable': False,
'is_internal': True,
'last_updated': 1732304976,
'name': 'testDamien',
'overall_alert_level': 'warn',
'page_load_alert_time_in_ms': 30000,
'polling_interval': 5,
'properties': [],
'role_privileges': [],
'schema': 'http',
'status': 'dead-collector',
'steps': [{'auth': None,
'description': '',
'enable': True,
'follow_redirection': True,
'fullpage_load': False,
'http_body': '',
'http_headers': '',
'http_method': 'GET',
'http_version': '1.1',
'invert_match': False,
'keyword': 'Alive',
'label': '',
'match_type': 'plain',
'name': '__step0',
'path': '',
'post_data_edit_type': None,
'req_script': '',
'req_type': 'config',
'require_auth': False,
'resp_script': '',
'resp_type': 'config',
'schema': 'http',
'status_code': '',
'timeout': 30,
'type': 'script',
'url': '',
'use_default_root': True}],
'stop_monitoring': False,
'stop_monitoring_by_folder': False,
'template': None,
'test_location': {'all': True,
'collector_ids': [],
'collectors': [],
'smg_ids': []},
'transition': 5,
'trigger_ssl_expiration_alert': False,
'trigger_ssl_status_alert': False,
'type': 'webcheck',
'use_default_alert_setting': False,
'use_default_location_setting': False,
'user_permission': 'write'}
And how it looks in the portal:
Anyone has any idea of what I may be missing ?
Thanks in advance.
DamienC
OP1 year agocnaStill no luck here. Still shows "dead collector" in the reply body. And in the portal is shows no collector at all.
Dumb question: Does your script have a block for "collectors" and one for "checkpoints" ?
If so, what do they look like in yours ?
Or do you only have that simple "test_location" block and that's it ?
...It's really annoying the LM support doesn't want to help with this...
DamienC
OP1 year agoThanks a lot for taking the time to reply. :)
I figured I was (maybe?) passing too much data.
Giving that a try in a few minutes and I'll update this post.
cna
·1 year agoI don't think you need to post all that for the test location.
I looked through my code and all i'm passing is the `collectorId` and `all` like this:
cna
·1 year agoForgot to include more details...
This took me a while to figure this out as well since the SDK docs aren't really clear. Since the SDK is just automatically generated via swagger, I often find myself digging through the API docs to try to piece together what's needed.
There's no equivalent doc for v3 API, but I can confirm this still is still the same in v3. https://www.logicmonitor.com/support/rest-api-developers-guide/v1/services/add-services
(also i just noticed that IDs 1 and 2 used in my example aren't valid... but the point still stands. find the IDs of our collectors and that's all you need.)