File: detect_network_issues.in

package info (click to toggle)
piuparts 1.6.0
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 72,532 kB
  • sloc: python: 8,240; sh: 4,367; makefile: 171
file content (100 lines) | stat: -rw-r--r-- 3,654 bytes parent folder | download | duplicates (3)
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
#!/bin/sh

# Copyright 2009-2018 Holger Levsen (holger@layer-acht.org)
# Copyright © 2011-2017 Andreas Beckmann (anbe@debian.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. If not, see <https://www.gnu.org/licenses/>


. @sharedir@/piuparts/lib/read_config.sh
. @sharedir@/piuparts/lib/write_log.sh

get_config_value MASTER global master-directory
get_config_value SECTIONS global sections
get_config_value HTDOCS global output-directory

STARTDATE=$(date -u +%s)
LOG_OUTPUT=$(mktemp)
LOG_PREFIX=$(mktemp)

#
# detect network/mirror problems
#

newline="
"
tab="	"
PATTERN=
DISPLAY_PATTERN=

add_pattern()
{
	PATTERN="${PATTERN:+${PATTERN}|}($1)"
	DISPLAY_PATTERN="${DISPLAY_PATTERN:+${DISPLAY_PATTERN}${newline}}${tab}$1"
}

add_pattern "Cannot initiate the connection to"
add_pattern "Hash Sum mismatch"
add_pattern "Failed to fetch.*Could not resolve"
add_pattern "Failed to fetch.*Something wicked happened resolving"
add_pattern "Failed to fetch.*Unable to connect to"
add_pattern "E: Method http has died unexpectedly"
add_pattern "Some index files failed to download, they have been ignored, or old ones used instead."
add_pattern "Some index files failed to download. They have been ignored, or old ones used instead."
add_pattern "W: GPG error: .* Release: The following signatures were invalid: BADSIG"
add_pattern "W: GPG error: .* InRelease: The following signatures were invalid: NODATA"
add_pattern "W: GPG error: .* InRelease: Clearsigned file isn't valid, got 'NODATA'"
add_pattern "E: The repository '.*' does no longer have a Release file."
add_pattern "E: The repository '.*' no longer has a Release file."
add_pattern "E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing"
add_pattern "E: Version '.*' for '.*' was not found"
add_pattern 'E: Method file has died unexpectedly!'
add_pattern "E: Sub-process rred received a segmentation fault."
add_pattern "ERROR: Command failed \(status=-7\):.*'apt-get', 'update'"
add_pattern 'Package .* .* not found in .*(, .* is available)?'
add_pattern "AppStream system cache was updated, but problems were found: Metadata files have errors"

FILE=$(mktemp)
for SECTION in $SECTIONS ; do
	test -d $MASTER/$SECTION || continue
	for subdir in fail bugged affected untestable ; do
		test -d $MASTER/$SECTION/$subdir || continue
		grep -r -l -E --include '*.log' "$PATTERN" $MASTER/$SECTION/$subdir >> $FILE
	done
done
if [ -s $FILE ] ; then
	FINALDATE=$(date -u +%s)
	RUNTIME=$(date -u -d "0 $FINALDATE seconds - $STARTDATE seconds" +%T)
	(
		echo "Network problems detected! The following logfiles have been deleted:"
		echo
		echo "Those problems were found in failed logs by grep'ing for these patterns:"
		echo "$DISPLAY_PATTERN"
		echo
	) > $LOG_PREFIX
	(
		echo "$(date -u)"
		echo "Runtime: $RUNTIME"
		echo
		for log in $(sort -u $FILE)
		do
			echo "$log" | cut -d "/" -f5-
			grep -E "$PATTERN" "$log" 2>/dev/null | perl -e 'print grep !$seen{$_}++, <>;' | head -n 10 | sed "s/^/${tab}/"
			rm -f "$log"
		done
		echo
	) > $LOG_OUTPUT
	publish_logs $LOG_OUTPUT $LOG_PREFIX $HTDOCS network_issues
fi
rm $FILE