1+ #! /usr/bin/env bash
2+ # Licensed to the Apache Software Foundation (ASF) under one
3+ # or more contributor license agreements. See the NOTICE file
4+ # distributed with this work for additional information
5+ # regarding copyright ownership. The ASF licenses this file
6+ # to you under the Apache License, Version 2.0 (the
7+ # "License"); you may not use this file except in compliance
8+ # with the License. You may obtain a copy of the License at
9+ #
10+ # http://www.apache.org/licenses/LICENSE-2.0
11+ #
12+ # Unless required by applicable law or agreed to in writing,
13+ # software distributed under the License is distributed on an
14+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+ # KIND, either express or implied. See the License for the
16+ # specific language governing permissions and limitations
17+ # under the License.
18+
19+ # getRouterAlerts.sh --- Send the alerts from routerServiceMonitor.log to Management Server
20+
21+ # set -x
22+
23+ filename=/var/log/routerServiceMonitor.log # Monitor service log file
24+ if [ -n " $1 " -a -n " $2 " ]
25+ then
26+ reqDateVal=$( date -d " $1 $2 " " +%s" ) ;
27+ else
28+ reqDateVal=0
29+ fi
30+ if [ -f $filename ]
31+ then
32+ while read line
33+ do
34+ if [ -n " $line " ]
35+ then
36+ dateval=` echo $line | awk ' {print $1, $2}' `
37+ IFS=' ,' read -a array <<< " $dateval"
38+ dateval=${array[0]}
39+
40+ toDateVal=$( date -d " $dateval " " +%s" )
41+
42+ if [ " $toDateVal " -gt " $reqDateVal " ]
43+ then
44+ alerts=" $line \n$alerts "
45+ else
46+ break
47+ fi
48+ fi
49+ done < <( tac $filename )
50+ fi
51+ if [ -n " $alerts " ]; then
52+ echo $alerts
53+ else
54+ echo " No Alerts"
55+ fi
0 commit comments