summaryrefslogtreecommitdiffstats
path: root/frikanalen/bin/check_stream_images
blob: f0224ded20c5bcc08ed9c3a1f14e7ebc8aa12cab (plain)
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
#!/bin/sh
#
# Nagios test to detect a hanging video stream.
# Fetch two images from the Video stream and make sure they differ.
# Report error if they stay the same.
#
# Remember: apt-get install findimagedupes mplayer

delay=35 # seconds
tmpdir=/tmp

getframe() {
    (
	cd $tmpdir # Make sure temp file is stored in temp directory
	url="$1"
	filename="$2"
	mplayer -ss 0:00 -frames 1 -vo jpeg -nosound $url > /dev/null 2>&1
	mv 00000001.jpg $filename
    )
}

for bin in mplayer findimagedupes ; do
    if type $bin >/dev/null 2>&1 ; then
	:
    else
	echo "WARNING: Unable to find $bin binary."
	exit 1
    fi
done

if [ ! "$1" ] ; then
    cat <<EOF
Usage: check_stream_images <url>
Example: check_xstream_images http://voip.nuug.no:8000/frikanalen.ogv
EOF
    exit 1
else
    url="$1"
fi

timestamp=$(date +%Y%m%dT%H:%M:%S)
first="$tmpdir/first-$timestamp-$$.jpeg"
second="$tmpdir/second-$timestamp-$$.jpeg"

getframe "$url" "$first"
sleep $delay
getframe "$url" "$second"

if findimagedupes "$first" "$second" | grep -q "$second" ; then
    rm $first $second
    echo "CRITICAL: Two images taken $delay seconds apart were (almost) identical"
    exit 2
else
    rm $first $second
    echo "OK: Two images taken $delay seconds apart differ"
    exit 0
fi