Forum Discussion

Shack's avatar
Shack
Icon for Advisor rankAdvisor
5 months ago

Collector Name Property

I need to set a property on my collectors that equals the name of the collector.  Name meaning the name of the server.  

##HOST## cannot be used during collector down events and all we have to work with is ##AGENT_DESCRIPTION## which can be set to anything.

Does anyone have a script that will get the name of the collector and set the value as a custom collector property?

I feel like a token for this should exist and I am pretty sure I put this in as a suggestion years ago.  

  • Anonymous's avatar
    Anonymous

    Why not just make the ##AGENT_DESCRIPTION## have the value of the collector's host's name?

    LM borked their website and both the swagger and sdk docs are giving 404 errors. Otherwise I'd point you to it.

  • That was my other thought but when I was looking at the API docs I didn't see a way to update the collector description.  Might of read through it too fast.  

  • Anonymous's avatar
    Anonymous

    The hostname field in the API response should have the name of the device. Looks like this should do it:

    from lm import lm
    collectors = {x.id:x for x in lm.get_collector_list(size=1000).items}
    for id, collector in collectors.items():
        if collector.description != collector.hostname:
            result = lm.update_collector_by_id(id,{"description": collector.hostname, "collectorGroupId": collector.collector_group_id})
            print(f"Collector {id}\n\tOld description: {collector.description}\n\tNew description: {result.description}")