Mass removing services from interfaces

faq
how-to
#1

What’s the easiest approach to delete service XYZ from all nodes in an OpenNMS instance?

#2

If you delete a service via the web interface, it uses this event:

send-event.pl --nodeid $nodeid --interface $iface --service $service uei.opennms.org/nodes/deleteService

There are three tables that contain the above data: service, ifservices, and ipinterface.

To convert the servicename to a serviceid:

select serviceid from service where servicename = 'XYZ'; 

To get the list of interfaces that have the service defined on them:

select * from ifservices where serviceid in ( select serviceid from service where servicename = 'XYZ' );

To get a list of send-event.pl commands to remove those services:

 select 'send-event.pl --nodeid ' || IP.nodeid || ' --interface ' || IP.ipaddr || ' --service ' || S.servicename || '   uei.opennms.org/nodes/deleteService;' from ipinterface IP, ifservices IFS, service S where IP.id = IFS.ipinterfaceid and IFS.serviceid = S.serviceid and S.servicename = 'XYZ';

Then just send that output to bash to delete those services.

psql -U opennms -c "...." | bash
3 Likes