-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnsquerylogs.config
166 lines (153 loc) · 3.96 KB
/
dnsquerylogs.config
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
packages:
yum:
awslogs: []
tcpdump: []
files:
/etc/rc.d/init.d/dnsquerylogs:
mode: "000755"
owner: root
group: root
content: |
#!/bin/sh
#
# dnsquerylogs Start/Stop the DNS Query Logs agent
#
# chkconfig: 2345 1 99
# description: This script is responsible for running tcpdump as a \
# daemon in order to capture DNS Query Logs
### BEGIN INIT INFO
# Provides: dnsquerylogs
# Required-Start: networking
# Required-Stop: networking
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: Capture DNS Query Logs.
# Description: This script is responsible for running tcpdump as a \
# daemon in order to capture DNS Query Logs
### END INIT INFO
# Source function library.
. /etc/init.d/functions
prog=dnsquerylogs
exec="/usr/sbin/tcpdump"
pidfile=/var/run/dnsquerylogs.pid
logfile=/var/log/dnsqueries.log
retry_count=5
start() {
if [ "${UID}" -ne 0 ] ; then
echo "User has insufficient privilege."
exit 4
fi
[ -x ${exec} ] || exit 5
if [ -e ${pidfile} ]; then
rh_status
else
echo -n "Starting ${prog} to capture DNS Query Logs... "
PID=$(nohup ${exec} port 53 > ${logfile} 2>&1 & echo $!)
echo ${PID} > ${pidfile}
echo_success
echo
fi
}
stop() {
if [ "${UID}" -ne 0 ] ; then
echo "User has insufficient privilege."
exit 4
fi
if [ -e "${pidfile}" ]; then
echo -n "Shutting down DNS Query Logs... "
kill $(cat ${pidfile})
retval=$?
if [ ${retval} -eq 0 ]; then
rm -f ${pidfile}
echo_success
else
echo_failure
fi
else
# not running, but that's OK
echo_success
fi
echo
}
restart() {
rh_status_q && stop
start
}
rh_status() {
status -p ${pidfile} ${prog}
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
rh_status
;;
restart)
restart
;;
*)
echo "Usage: dnsquerylogs {start|stop|status|restart}"
exit 1
;;
esac
exit $?
/etc/logrotate.elasticbeanstalk.hourly/logrotate.cnote.dnsquery.conf:
mode: "000644"
owner: root
group: root
content: |
/var/log/dnsqueries.log {
size 10M
missingok
notifempty
rotate 5
compress
copytruncate
dateext
dateformat -%s
olddir /var/log/rotated
}
/etc/cron.hourly/cron.logrotate.cnote.dnsquery.conf:
mode: "000755"
owner: root
group: root
content: |
#!/bin/sh
test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate -f /etc/logrotate.elasticbeanstalk.hourly/logrotate.cnote.dnsquery.conf
/etc/awslogs/config/dnsquerylogs.conf:
mode: "000600"
owner: root
group: root
content: |
[/var/log/dnsqueries.log]
log_group_name = `{"Fn::Join":["/", ["/aws/elasticbeanstalk", { "Ref":"AWSEBEnvironmentName" }, "var/log/dnsqueries.log"]]}`
log_stream_name = {instance_id}
file = /var/log/dnsqueries.log
services:
sysvinit:
dnsquerylogs:
enabled: true
ensureRunning: true
files:
- /etc/rc.d/init.d/dnsquerylogs
- /etc/logrotate.elasticbeanstalk.hourly/logrotate.cnote.dnsquery.conf
packages:
yum:
tcpdump: []
commands:
01:
command: chkconfig awslogs on
02:
command: chkconfig dnsquerylogs on
03:
command: service awslogs restart
04:
command: service dnsquerylogs restart