dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / fm / notify / smtp-notify / common / process_msg_template.sh
blobeb9bcf82dba53f6c9f29eff84583d8712f680898
1 #!/bin/sh
4 # CDDL HEADER START
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.
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.
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]
21 # CDDL HEADER END
25 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
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.
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.
37 # We use all-caps for the committed macro names to avoid colliding
38 # with an actual event payload member name.
40 # Usage: process_msg_template.sh <infile> <outfile> <code> <severity>
44 # Verify template exists, is readable and is an ascii text file
46 if [ ! -e $1 ] || [ ! -r $1 ]; then
47 exit 1
50 /usr/bin/file $1 | grep "ascii text" > /dev/null
51 if [ $? != 0 ]; then
52 exit 1
55 tmpfile1=$2;
56 tmpfile2=`/usr/bin/mktemp -p /var/tmp`
58 cat $1 | sed s/\%\<CODE\>/$3/g > $tmpfile1
59 cat $tmpfile1 | sed s/\%\<UUID\>/\%\<uuid\>/g > $tmpfile2
60 cat $tmpfile2 | sed s/\%\<CLASS\>/\%\<class\>/g > $tmpfile1
61 cat $tmpfile1 | sed s/\%\<SEVERITY\>/$4/g > $tmpfile2
62 cat $tmpfile2 | sed s/\%\<FMRI\>/svc\:\\/\%\<attr.svc.svc-name\>\:\%\<attr.svc.svc-instance\>/g > $tmpfile1
63 cat $tmpfile1 | sed s/\%\<FROM-STATE\>/\%\<attr.from-state\>/g > $tmpfile2
64 cat $tmpfile2 | sed s/\%\<TO-STATE\>/\%\<attr.to-state\>/g > $tmpfile1
65 cat $tmpfile1 | sed s/\%\<HOSTNAME\>/\%h/g > $tmpfile2
66 cat $tmpfile2 | sed s/\%\<URL\>/\%s/g > $tmpfile1
67 rm -f $tmpfile2
68 exit 0