From 50a11ca38c7c80a17e86d9095df3a513ab4acb5e Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sat, 17 Apr 2010 21:52:44 -0400 Subject: [PATCH] Added the parse_object_definitions script. --- utils/parse_object_definitions | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 utils/parse_object_definitions diff --git a/utils/parse_object_definitions b/utils/parse_object_definitions new file mode 100755 index 0000000..dd30368 --- /dev/null +++ b/utils/parse_object_definitions @@ -0,0 +1,48 @@ +#!/bin/bash +# +# Parse the object names out of Nagios' xdata/xodtemplate.h, and +# convert them to their definition format. +# +# Operates on whatever file you give it, like the other utilities. +# + +EXIT_USAGE=1 +EXIT_INPUT_FILE_DOESNT_EXIST=2 +EXIT_OUTPUT_FILE_EXISTS=3 + +if [ $# -lt 2 ]; then + echo "Usage: $0 " + exit $EXIT_USAGE +fi + + +INFILE="$1" +OUTFILE="$2" + +if [ ! -f "$INFILE" ]; then + echo "Error: input file $INFILE doesn't exist." + exit $EXIT_INPUT_FILE_DOESNT_EXIST +fi + +if [ -f "$OUTFILE" ]; then + echo "Error: output file $OUTFILE already exists." + exit $EXIT_OUTPUT_FILE_EXISTS +fi + +# Common options. Color screws up the output. +GREP="grep --extended-regexp --color=never" + +# Grep grabs all of the "#define XODTEMPLATE_..." lines, except for +# XODTEMPLATE_NONE, which ain't real. +# +# Sed removes the "XODTEMPLATE_" prefixes, then tr lowercases everything. +# +# Oh and we sort everything, add "define ", and surround each line with +# quotes, because we can get away with it here. +# +$GREP --only-matching '[[:space:]]XODTEMPLATE_[[:alnum:]_]+' "$INFILE" \ + | $GREP -v 'XODTEMPLATE_NONE' \ + | sed 's/ XODTEMPLATE_//g' \ + | tr '[A-Z]' '[a-z]' \ + | sort \ + | sed -e 's/^/\"define /g' -e 's/$/\"/g' >> "$OUTFILE" -- 2.44.2