-
Notifications
You must be signed in to change notification settings - Fork 1
/
ipa-sss-dat
executable file
·260 lines (189 loc) · 6.57 KB
/
ipa-sss-dat
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/bin/bash
# This script comes with ABSOLUTELY NO WARRANTY, use at own risk
# Copyright (C) 2021 Osiris Alejandro Gomez <[email protected]>
#
# 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 3 of the License, or
# 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. If not, see <http://www.gnu.org/licenses/>.
# shellcheck disable=SC1090
# shellcheck disable=SC1091
# shellcheck disable=SC2129
[[ -n "$BASH_DEBUG" ]] && set -x
DIR_BIN="$(dirname "$0")" && source "$DIR_BIN/ipa-src-cfg"
function usage()
{
cat << EOF
## \`$BIN\` Generate .dat file to plot SynLog
### Usage
\`\`\`bash
$BIN [IPA_SSS_SYN_LOG] [DATE]
\`\`\`
### Description
Generate data file from \`ipa-sss-syn.log\` to generate plot
### Examples
\`\`\`bash
$BIN ipa-sss-syn.log
$BIN ipaai-2022-02-22-ipa-sss-syn.log 2022-02-22
\`\`\`
EOF
exit 0
}
[[ "$1" =~ ^[-]+(h|help) ]] && usage
function params()
{
[[ -z "$1" ]] && die "EMPTY LOG FILE"
TMP="$1"
[[ -e "$1" ]] || die "NOT FOUND LOG FILE $TMP"
DATE="$(date +%F)"
[[ -z "$2" ]] || DATE="$2"
}
function validate()
{
[[ -z "$IPA_SRV" ]] && cfg 'IPA_SRV'
[[ -z "$DIR_DAT" ]] && cfg 'DIR_DAT'
[[ -d "$DIR_DAT" ]] || die "NOT FOUND DIR $DIR_DAT"
[[ -e "$IPA_SRV" ]] || die "NOT FOUND FILE $IPA_SRV"
}
function filter()
{
LOG="$DIR_DAT/$DATE-dat.log"
grep -E "^$DATE" "$TMP" > "$LOG"
SRV="$DIR_DAT/$DATE-srv.log"
grep -E "^$DATE" "$IPA_SRV" | tr '_' ' ' > "$SRV"
[[ -s "$SRV" ]] || stderror "EMPTY FILE $SRV"
}
function defaults()
{
SEC="$DIR_DAT/$DATE-seconds.dat"
SSY="$DIR_DAT/$DATE-sync.dat"
SNO="$DIR_DAT/$DATE-no-sync.dat"
TOT="$DIR_DAT/$DATE-total.dat"
# SYN ERROR
SER="$DIR_DAT/$DATE-syn-err.dat"
# CRON
SCR="$DIR_DAT/$DATE-crn-syn.dat"
SCW="$DIR_DAT/$DATE-crn-syw.dat"
NCR="$DIR_DAT/$DATE-crn-nos.dat"
NCW="$DIR_DAT/$DATE-crn-now.dat"
# IVR
SIV="$DIR_DAT/$DATE-ivr-syn.dat"
SIW="$DIR_DAT/$DATE-ivr-syw.dat"
NIV="$DIR_DAT/$DATE-ivr-nos.dat"
NIW="$DIR_DAT/$DATE-ivr-now.dat"
# AID
SAI="$DIR_DAT/$DATE-aid-syn.dat"
NAI="$DIR_DAT/$DATE-aid-nos.dat"
SAW="$DIR_DAT/$DATE-aid-syw.dat"
NAW="$DIR_DAT/$DATE-aid-now.dat"
# IPS
TIM="$DIR_DAT/$DATE-time.dat"
SEP=' '
LDAP="$DIR_DAT/$DATE-ldap.dat"
LDAS="$DIR_DAT/$DATE-ldas.dat"
KRB5="$DIR_DAT/$DATE-krb5.dat"
LSOF="$DIR_DAT/$DATE-lsof.dat"
AV01="$DIR_DAT/$DATE-av01.dat"
}
function srv2dat()
{
awk '{print $2, $3}' "$SRV" | sed 's/389://g' > "$LDAP"
awk '{print $2, $4}' "$SRV" | sed 's/636://g' > "$LDAS"
awk '{print $2, $5}' "$SRV" | sed 's/88://g' > "$KRB5"
awk '{print $2, $10}' "$SRV" | sed 's/LSOF://g' > "$LSOF"
awk '{print $2, $13}' "$SRV" | tr -d ',' > "$AV01"
}
function log2dat()
{
# FIXME capture seconds=[0-9]+$
awk -F "$SEP" '{print $2,$NF}' "$LOG" | tr '=' ' ' | awk '{print $1,$3}' > "$SEC"
awk -F "$SEP" '/sss_cache=1/ {print $2,$NF}' "$LOG" | tr '=' ' ' | awk '{print $1,$3}' > "$SSY"
awk -F "$SEP" '/sss_cache=0/ {print $2,$NF}' "$LOG" | tr '=' ' ' | awk '{print $1,$3}' > "$SNO"
# ERR
awk -F "$SEP" '/error=[0-9]{2}/ {print $2,$23}' "$LOG" | tr '=' ' ' | awk '{print $1,$3}' > "$SER"
# AID
awk -F "$SEP" "/ipaai.*sss_cache=1/ {print \$2,\$NF}" "$LOG" | tr '=' ' ' | awk '{print $1,$3}' > "$SAI"
awk -F "$SEP" "/ipaai.*sss_cache=0/ {print \$2,\$NF}" "$LOG" | tr '=' ' ' | awk '{print $1,$3}' > "$NAI"
awk '($2 >= 20) {print $0}' "$SAI" > "$SAW"
awk '($2 >= 20) {print $0}' "$NAI" > "$NAW"
# IVR
awk -F "$SEP" "/ipaivr.*sss_cache=1/ {print \$2,\$NF}" "$LOG" | tr '=' ' ' | awk '{print $1,$3}' > "$SIV"
awk -F "$SEP" "/ipaivr.*sss_cache=0/ {print \$2,\$NF}" "$LOG" | tr '=' ' ' | awk '{print $1,$3}' > "$NIV"
awk '($2 >= 20) {print $0}' "$SIV" > "$SIW"
awk '($2 >= 20) {print $0}' "$NIV" > "$NIW"
# CRN
awk -F "$SEP" "/root.*sss_cache=1/ {print \$2,\$NF}" "$LOG" | tr '=' ' ' | awk '{print $1,$3}' > "$SCR"
awk -F "$SEP" "/root.*sss_cache=0/ {print \$2,\$NF}" "$LOG" | tr '=' ' ' | awk '{print $1,$3}' > "$NCR"
awk '($2 >= 20) {print $0}' "$SCR" > "$SCW"
awk '($2 >= 20) {print $0}' "$NCR" > "$NCW"
}
function totals()
{
# IVR
TOT_SIV="$(wc -l "$SIV" | awk '{print $1}')" # ivr cache=1
TOT_NIV="$(wc -l "$NIV" | awk '{print $1}')" # ivr cache=0
TOT_IVR="$((TOT_SIV+TOT_NIV))"
TOT_SIW="$(wc -l "$SIW" | awk '{print $1}')" # ivr cache=1 >20s
TOT_NIW="$(wc -l "$NIW" | awk '{print $1}')" # ivr cache=0 >20s
TOT_IVW="$((TOT_SIW+TOT_NIW))"
# AID
TOT_SAI="$(wc -l "$SAI" | awk '{print $1}')" # aid cache=1
TOT_NAI="$(wc -l "$NAI" | awk '{print $1}')" # aid cache=0
TOT_AID="$((TOT_SAI+TOT_NAI))"
TOT_SAW="$(wc -l "$SAW" | awk '{print $1}')" # aid cache=1 >20s
TOT_NAW="$(wc -l "$NAW" | awk '{print $1}')" # aid cache=0 >20s
TOT_AIW="$((TOT_SAW+TOT_NAW))"
TOT_SCW="$(wc -l "$SCW" | awk '{print $1}')" # crn cache=1 >20s
TOT_NCW="$(wc -l "$NCW" | awk '{print $1}')" # crn cache=0 >20s
TOT_CRW="$((TOT_SCW+TOT_NCW))"
# TOT
TOT_IVR_AID="$((TOT_IVR+TOT_AID))"
TOT_IVW_AIW="$((TOT_IVW+TOT_AIW))"
OVW="$DIR_DAT/$DATE-ovw.dat"
true > "$OVW"
printf "%s " "$DATE" >> "$OVW"
printf "%s " "$TOT_SIV" >> "$OVW" # ivr cache=1
printf "%s " "$TOT_NIV" >> "$OVW" # ivr cache=0
printf "%s " "$TOT_IVR" >> "$OVW" # ivr cache=0 + cache=1
printf "%s " "$TOT_SIW" >> "$OVW" # ivr cache=1 >20s
printf "%s " "$TOT_NIW" >> "$OVW" # ivr cache=0 >20s
printf "%s " "$TOT_IVW" >> "$OVW" # ivr cache=0 >20s + cache=1 >20s
printf "%s " "$TOT_SAI" >> "$OVW" # aid cache=1
printf "%s " "$TOT_NAI" >> "$OVW" # aid cache=0
printf "%s " "$TOT_AID" >> "$OVW" # aid cache=0 >20s
printf "%s " "$TOT_SAW" >> "$OVW" # aid cache=0 + cache=1
printf "%s " "$TOT_NAW" >> "$OVW" # aid cache=1 >20s
printf "%s " "$TOT_AIW" >> "$OVW" # aid cache=0 >20s + cache=1 >20s
printf "%s " "$TOT_SCW" >> "$OVW" # crn cache=0 + cache=1
printf "%s " "$TOT_NCW" >> "$OVW" # crn cache=1 >20s
printf "%s " "$TOT_CRW" >> "$OVW" # crn cache=0 >20s + cache=1 >20s
printf "%s " "$TOT_IVR_AID" >> "$OVW" # ivr + aid
printf "%s " "$TOT_IVW_AIW" >> "$OVW" # ivr + aid >20s
awk '{print $1}' "$SEC" \
| sort \
| uniq -c \
| awk '{print $2,$1}' \
| sort > "$TOT"
awk '{print $2}' "$SEC" \
| sort > "$TIM"
}
function main()
{
config
params "$@"
validate
filter
defaults
srv2dat
log2dat
totals
}
main "$@"