News:

We really need your input in this questionnaire

Main Menu

Bulk DCI removal

Started by woodrivercontrols, May 07, 2024, 11:43:52 PM

Previous topic - Next topic

woodrivercontrols

I have somehow wound up with a large number of nodes (>1500) that have a DCI that was created by a template dci with instance discovery, but the instance discovery DCI is no longer part of the template. Because of this, if I want to remove these DCI (which I do), I have to go through every node and individually delete each one.
If I go to edit the DCI, I get the popup that says 'This DCI was created through instance discovery' , but there is no instance discovery DCI left on the node.
I am at a loss, it seems there is no way to automate deleting a DCI through API or scripting, and I really don't want to pay someone to go through all of these nodes and sort out which DCI need to be deleted.
Is there a way to bulk delete DCI that I am missing?

Alex Kirhenshtein

They should've been removed when instance DCI was removed from the template. Also "nxdbmgr check" should handle that, if I remember correctly.

Anyway, you can delete them either via API (e.g. using nxshell or custom java app) or by modifying database directly. I'd recommend API.

Something like this (do not run as-is, just an example):
for node in [o for o in session.allObjects if isinstance(o, objects.Node)]:
    c = session.openDataCollectionConfiguration()
    try:
        items_to_remove = []
        for item in c.items:
            if item.name == 'System.CPU.Usage':
                items_to_remove.append(item.id)
       
        for item_id in items_to_remove:
            c.deleteObject(item_id)
       
        if len(items_to_remove) > 0:
            c.commit()
    finally:
        c.close()