Importing .xml Backups into OpenNMS

TopTier Active Directory Leave a Comment

Myself and a colleague were going through a migration of our monitoring system called OpenNMS from 1 server in 1 datacenter to the other server in another datacenter.

For that, we have received .xml files representing requisitions on the source server.

OpenNMS usually doesn’t play well with those files, so with help of some 3rd party documentation and guides, we have developed this quick and easy to follow guide, which should help you if you ever need to migrate your OpenNMS instance from one server to the other.

Upload XML files to the OpenNMS Server

Via SFTP, to somewhere like /opt/opennms/etc/tmp as a start.

Create a script on the NMS server:

nano /opt/opennms/etc/import-req.sh

Paste the following in the script:


#!/bin/bash
OPENNMS_HOST=localhost
OPENNMS_USER=username
OPENNMS_PASS=password
OPENNMS_PORT=8980

GRAYLOG_HOST=localhost
GRAYLOG_USER=username
GRAYLOG_PASS=password
GRAYLOG_PORT=9000


# set -x
echo -n "Ensure the ReST API is running before setup "
until $(curl -L --output /dev/null --silent --head --fail http://${OPENNMS_HOST}:8980); do
printf '.'
sleep 2
done
echo " DONE"

echo -n "Create Requisition ... "
curl -s -u ${OPENNMS_USER}:${OPENNMS_PASS} \
-X POST \
-H "Content-Type: application/xml" \
-H "Accept: application/xml" \
-d @"tmp/REQUESITION NAME.xml" \
http://${OPENNMS_HOST}:${OPENNMS_PORT}/opennms/rest/requisitions
echo "DONE"


echo -n "Import requisition ... "
curl -s -u ${OPENNMS_USER}:${OPENNMS_PASS} \
-X PUT \
http://${OPENNMS_HOST}:${OPENNMS_PORT}/opennms/rest/requisitions/REQUESITION%20NAME/import
echo "DONE"


You need to pay attention to two lines:

Warning: this is case sensitive, as it is Linux. Paths and filenames must be correct.

In “Create Requesition” :

-d @”tmp/REQUESITION NAME.xml” \

Will refer to the path to the XML you are importing.

In “Import Requisition” you will reference the requesition’s name in the URL, with %20 for any spaces.

http://${OPENNMS_HOST}:${OPENNMS_PORT}/opennms/rest/requisitions/REQUESITION%20NAME/import

Save + Run the script:

bash import-req.sh

This should import the requisition and process the nodes.

Troubleshooting

Sometimes I found that the nodes were not processed immediately after running the script.

You need to go into the admin panel to correct that.

Click “Manage Provisioning Requisitions”.

And manually “synchronize” that one:

Leave a Reply

Your email address will not be published. Required fields are marked *