Module: check_mk
Branch: master
Commit: 432eabcb3c4d18c115dcdbc0b3ceb6f3469843d9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=432eabcb3c4d18…
Author: Florian Heigl <fh(a)mathias-kettner.de>
Date: Fri Aug 24 12:08:08 2012 +0200
Document inventory helper script
---
doc/treasures/inventory_helper.sh | 32 ++++++++++++++++++++++++--------
1 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/doc/treasures/inventory_helper.sh b/doc/treasures/inventory_helper.sh
index 844bff3..0f90fe5 100644
--- a/doc/treasures/inventory_helper.sh
+++ b/doc/treasures/inventory_helper.sh
@@ -1,28 +1,44 @@
#!/bin/sh
+# A script to
+# * identify systems where the inventory check has fired
+# * output their list including the services that are unmonitored add
+# * then reinventorize them
+# * reschedule the inventory check to clean up
+# The script does not remove any services!
-# A script to get systems where the inventory check has fired
-# then output those including the services they'll add
-# then reinventorize them
-# then reschedule the inventory check to clean up
+# this works as intended. If you have a flaky enviroment, you
+# might want to filter for hosts that are in state up before the
+# inventory goes looking for them.
reinventory()
{
-check_mk --automation inventory new $HOST
-
-echo "COMMAND [`date +%s`] SCHEDULE_FORCED_SVC_CHECK;$HOST;Check_MK inventory;`date
+%s`" | lq
+now=`date +%s`
+
+# Use the automation API to run an inventory, only for new objects.
+check_mk --automation inventory new $HOST >/dev/null
+
+# Then reschedule the inventory check right now to clear up.
+# (currently we're running it just once a day at the same time on all hosts)
+echo "COMMAND [$now] SCHEDULE_FORCED_SVC_CHECK;$HOST;Check_MK inventory;$now" |
lq
}
+# Here we grab the hosts where the inventory check found something.
+# we look at the check output because we don't know what serverity
+# is configured for the inventory check by a user.
+# The only info we store is the host name and the list of detected services.
+# (so you can log the info)
+
INVENTORY_INFO=`echo "GET services
Columns: host_name long_plugin_output
Filter: description = Check_MK inventory
Filter: plugin_output !~~ no unchecked" | lq`
-if [ $INVENTORY_INFO != "" ]; then
+if [ "$INVENTORY_INFO" != "" ]; then
HOSTS=`echo "$INVENTORY_INFO" | cut -f1 -d\;`
echo "$INVENTORY_INFO"
for HOST in "$HOSTS" ; do