f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#!/bin/sh
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# CDDL HEADER START
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# The contents of this file are subject to the terms of the
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# Common Development and Distribution License (the "License").
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# You may not use this file except in compliance with the License.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# or http://www.opensolaris.org/os/licensing.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# See the License for the specific language governing permissions
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# and limitations under the License.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# When distributing Covered Code, include this CDDL HEADER in each
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# If applicable, add the following below this CDDL HEADER, with the
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# fields enclosed by brackets "[]" replaced with your own identifying
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# information: Portions Copyright [yyyy] [name of copyright owner]
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# CDDL HEADER END
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# This is a simple helper script for smtp-notify which looks for certain
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# expansion macros, which we've committed and converts them to valid
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# libfmd_msg macros which directly reference event payload members.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# This allows us to change event payload names or alter the libfmd_msg
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# expansion macro syntax without breaking user-supplied message body
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# templates.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# We use all-caps for the committed macro names to avoid colliding
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# with an actual event payload member name.
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# Usage: process_msg_template.sh <infile> <outfile> <code> <severity>
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby# Verify template exists, is readable and is an ascii text file
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby#
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyif [ ! -e $1 ] || [ ! -r $1 ]; then
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby exit 1
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyfi
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby/usr/bin/file $1 | grep "ascii text" > /dev/null
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyif [ $? != 0 ]; then
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby exit 1
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyfi
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbytmpfile1=$2;
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbytmpfile2=`/usr/bin/mktemp -p /var/tmp`
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltby
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbycat $1 | sed s/\%\<CODE\>/$3/g > $tmpfile1
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbycat $tmpfile1 | sed s/\%\<UUID\>/\%\<uuid\>/g > $tmpfile2
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbycat $tmpfile2 | sed s/\%\<CLASS\>/\%\<class\>/g > $tmpfile1
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbycat $tmpfile1 | sed s/\%\<SEVERITY\>/$4/g > $tmpfile2
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbycat $tmpfile2 | sed s/\%\<FMRI\>/svc\:\\/\%\<attr.svc.svc-name\>\:\%\<attr.svc.svc-instance\>/g > $tmpfile1
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbycat $tmpfile1 | sed s/\%\<FROM-STATE\>/\%\<attr.from-state\>/g > $tmpfile2
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbycat $tmpfile2 | sed s/\%\<TO-STATE\>/\%\<attr.to-state\>/g > $tmpfile1
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbycat $tmpfile1 | sed s/\%\<HOSTNAME\>/\%h/g > $tmpfile2
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbycat $tmpfile2 | sed s/\%\<URL\>/\%s/g > $tmpfile1
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyrm -f $tmpfile2
f6e214c7418f43af38bd8c3a557e3d0a1d311cfaGavin Maltbyexit 0