3 # Copyright 2011 Peter Palfrader
4 # Copyright 2014 Hendrik Köhler
6 # Permission is hereby granted, free of charge, to any person obtaining
7 # a copy of this software and associated documentation files (the
8 # "Software"), to deal in the Software without restriction, including
9 # without limitation the rights to use, copy, modify, merge, publish,
10 # distribute, sublicense, and/or sell copies of the Software, and to
11 # permit persons to whom the Software is furnished to do so, subject to
12 # the following conditions:
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 AVAIL = '/proc/sys/kernel/random/entropy_avail'
32 parser = optparse.OptionParser()
33 parser.add_option("-r", "--retries", dest="retries", metavar="NUM",
34 type="int", default=10,
35 help="Max number of retries [10].")
36 parser.add_option("-s", "--sleep", dest="sleep", metavar="MSECS",
37 type="int", default=250,
38 help="Amount of time to wait between reads [250msec].")
39 parser.add_option("-w", "--watermark", dest="watermark", metavar="BYTES",
40 type="int", default=800,
41 help="Minimum number of expected bytes in the entropy pool [800].")
42 (options, args) = parser.parse_args()
48 if not os.path.exists(AVAIL):
49 print "File %s does not exist."%(AVAIL)
54 while tries <= options.retries:
55 f = open('/proc/sys/kernel/random/entropy_avail')
56 avail = f.readline().rstrip()
58 print "Could not read anything from %s"%(AVAIL)
63 print "Did not read a number from %s, got '%s' instead"%(AVAIL, avail)
66 if avail >= options.watermark:
68 print "OK: %d bytes in the pool after %d attempts.|entropy=%d bytes"%(avail, tries, avail)
70 print "OK: %d bytes in the pool.|entropy=%d bytes"%(avail, avail)
74 time.sleep(1.0 * options.sleep / 1000)
77 print "WARNING: Too little entropy in the pool (min: %d, max: %d in %d reads)|entropy=%d bytes"%(min(values), max(values), tries-1, avail)
82 # vim:set shiftwidth=4: