0

Is there a way to get Openstack to run a script right after it creates or deletes a VM(both Windows and Linux)? This script has to be run on the host itself, not on the VM or guest it just created.

The purpose of this is to add/remove the host from our Nagios server automatically. Right now we are adding/removing the hosts on Nagios manually but this is not ideal since we create/delete VMs multiple times a day.

We can easily add a host on Nagios using the following API call:

curl -XPOST "http://10.25.5.2/nagiosxi/api/v1/config/host?apikey=5goacg8s&pretty=1" -d "host_name=openstack_vm_1&address=192.168.10.1&use=xiwizard_generic_host&force=1&applyconfig=1

If I can get Openstack to run the above command, replacing just the hostname and address for each VM it creates, that solves my problem. I can use something similar to remove the host from Nagios as well.

Keith
  • 4,637
  • 15
  • 25
Debianuser
  • 421
  • 4
  • 12
  • 29

1 Answers1

0

OpenStack has a CLI that you can use to pretty much do anything in regard to virtual hosts, containers, and so on. This means you can bundle the command to instantiate a host and the command to tell Nagios about the new host into a bash script, batch file, Powershell script, or whatever other script language you have available. Likewise, the command to delete a host instance and the command to remove said instance from Nagios can be bundled together into a teardown script.

Just glancing over this cheat sheet list of OpenStack commands, I don't see how it would be all that difficult to script. The caveat, of course, is that you cannot use the native OpenStack create or destroy commands all by themselves, you must "train" your support people into using your batch commands instead.

https://docs.openstack.org/user-guide/cli-cheat-sheet.html

George Erhard
  • 814
  • 6
  • 12