1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#! /bin/sh -e
# $Id: lr_log2xml.in,v 1.19 2001/11/13 19:47:19 flacoste Exp $
#
# Copyright (C) 2000-2001 Stichting LogReport Foundation LogReport@LogReport.org
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (see COPYING); if not, check with
# http://www.gnu.org/copyleft/gpl.html or write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
#
PROGRAM=lr_log2xml
id=${LR_ID:-UNSET}
tag="all all $id $PROGRAM"
echo >&2 "$tag info started with $*"
if test $# -lt 2
then
echo >&2 "$tag err please give at least 2 args, indicating superservice service (flags)"
exit 1
fi
# e.g. www
SUPERSERVICE="$1"; shift
# e.g. apache
SERVICE="$1"; shift
FLAGS="$@"
tag="$SUPERSERVICE $SERVICE $id $PROGRAM"
prefix="@prefix@"
etcdir="@sysconfdir@/@PACKAGE@"
if test -z "$TMPDIR"
then
echo >&2 "$tag err TMPDIR not set. did you source $etcdir/defaults?"
exit 1
fi
DLFFILE=$TMPDIR/$PROGRAM.$SERVICE.$id.$$.dlf
if test ! -d "$TMPDIR"
then
echo >&2 "$tag notice dir $TMPDIR does not exist, creating it"
if mkdir $TMPDIR
then
:
else
echo >&2 "$tag crit cannot create $TMPDIR, exiting"
exit 1
fi
fi
if touch $DLFFILE
then
:
else
echo >&2 "$tag crit cannot write $DLFFILE, exiting"
exit 1
fi
if test -z "$TODLF"
then
echo >&2 "$tag err TODLF not set. is '$SERVICE' a service? (You can find a list of valid SERVICEs in $etcdir/defaults.) If this script ($PROGRAM) was not run by lr_log2report, you should have manually sourced $etcdir/defaults, while SERVICE was set."
exit 1
fi
echo >&2 "$tag info gonna run $TODLF $FLAGS > $DLFFILE"
if $TODLF $FLAGS > $DLFFILE
then
:
else
echo >&2 "$tag crit $TODLF failed, exiting"
echo >&2 "$tag notice keeping $DLFFILE for debugging."
exit 1
fi
echo >&2 "$tag info finished $TODLF"
if test -r $HOME/.lire/etc/$SUPERSERVICE.cfg
then
REPORT_CFG=$HOME/.lire/etc/$SUPERSERVICE.cfg
else
REPORT_CFG=$etcdir/$SUPERSERVICE.cfg
fi
echo >&2 "$tag info gonna run lr_dlf2xml $SUPERSERVICE $REPORT_CFG $DLFFILE"
if lr_dlf2xml $SUPERSERVICE $REPORT_CFG $DLFFILE
then
:
else
echo >&2 "$tag crit lr_dlf2xml $DLFFILE $SUPERSERVICE failed, stuff on stdout probably bogus"
echo >&2 "$tag notice keeping $DLFFILE for debugging"
exit 1
fi
echo >&2 "$tag info lr_dlf2xml finished"
# now time_span, dlflines, loglines and errorlines is in database
# go deal with tmpfiles and archive
if test -n "$ARCHIVE"
then
# construct name for archivefile
TMPFILE=$TMPDIR/$PROGRAM.$SERVICE.$id.$$.time_span
if lr_db_fetch $id time_span > $TMPFILE
then
echo >&2 "$tag info lr_db_fetch $id timespan succeeded"
LR_TIME=`cat $TMPFILE`
rm $TMPFILE
else
echo >&2 "$tag crit lr_db_fetch $id timespan failed, exiting"
echo >&2 "$tag notice keeping $TMPFILE for debugging"
exit 1
fi
# LR_EXTID is used to identify e.g. the host the log came from
ARCHIVEDIR=$LR_ARCHIVEDIR/log/dlf/$SUPERSERVICE/complete/$LR_EXTID
ARCHIVEFILE=$ARCHIVEDIR/$LR_TIME
# name constructed, store it
echo >&2 "$tag notice storing $DLFFILE in $ARCHIVEFILE"
test -d $ARCHIVEDIR || mkdir -p $ARCHIVEDIR
mv $DLFFILE $ARCHIVEFILE
elif test -n "$KEEP"
then
echo >&2 "$tag notice keeping $DLFFILE on your request. remove manually."
else
rm $DLFFILE
fi
echo >&2 "$tag info stopped"
|