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