1#!/bin/sh
2
3#
4# CDDL HEADER START
5#
6# The contents of this file are subject to the terms of the
7# Common Development and Distribution License (the "License").
8# You may not use this file except in compliance with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23
24#
25# Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
26#
27
28#
29# This is a simple helper script for smtp-notify which looks for certain
30# expansion macros, which we've committed and converts them to valid
31# libfmd_msg macros which directly reference event payload members.
32#
33# This allows us to change event payload names or alter the libfmd_msg
34# expansion macro syntax without breaking user-supplied message body
35# templates.
36#
37# We use all-caps for the committed macro names to avoid colliding
38# with an actual event payload member name.
39#
40# Usage: process_msg_template.sh <infile> <outfile> <code> <severity>
41#
42
43#
44# Verify template exists, is readable and is an ascii text file
45#
46if [ ! -e $1 ] || [ ! -r $1 ]; then
47	exit 1
48fi
49
50/usr/bin/file $1 | grep "ascii text" > /dev/null
51if [ $? != 0 ]; then
52	exit 1
53fi
54
55tmpfile1=$2;
56tmpfile2=`/usr/bin/mktemp -p /var/tmp`
57
58cat $1 | sed s/\%\<CODE\>/$3/g > $tmpfile1
59cat $tmpfile1 | sed s/\%\<UUID\>/\%\<uuid\>/g > $tmpfile2
60cat $tmpfile2 | sed s/\%\<CLASS\>/\%\<class\>/g > $tmpfile1
61cat $tmpfile1 | sed s/\%\<SEVERITY\>/$4/g > $tmpfile2
62cat $tmpfile2 | sed s/\%\<FMRI\>/svc\:\\/\%\<attr.svc.svc-name\>\:\%\<attr.svc.svc-instance\>/g > $tmpfile1
63cat $tmpfile1 | sed s/\%\<FROM-STATE\>/\%\<attr.from-state\>/g > $tmpfile2
64cat $tmpfile2 | sed s/\%\<TO-STATE\>/\%\<attr.to-state\>/g > $tmpfile1
65cat $tmpfile1 | sed s/\%\<HOSTNAME\>/\%h/g > $tmpfile2
66cat $tmpfile2 | sed s/\%\<URL\>/\%s/g > $tmpfile1
67rm -f $tmpfile2
68exit 0
69