Repository: ocf/ocfweb

Issue:
Stop emailing us when there's a paper jam
```
A problem was encountered and reported via ocflib:

An exception occured in an ocfweb periodic function:

Traceback (most recent call last):
  File "/usr/share/python/ocfweb/lib/python3.4/site-packages/ocfweb/caching.py", line 56, in cache_lookup_with_fallback
    raise KeyError('Forcing miss as requested.')
KeyError: 'Forcing miss as requested.'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/share/python/ocfweb/lib/python3.4/site-packages/ocfweb/bin/run_periodic_functions.py", line 47, in run_periodic_functions
    pf.update()
  File "/usr/share/python/ocfweb/lib/python3.4/site-packages/ocfweb/caching.py", line 214, in update
    force_miss=True,
  File "/usr/share/python/ocfweb/lib/python3.4/site-packages/ocfweb/caching.py", line 66, in cache_lookup_with_fallback
    result = fallback()
  File "/usr/share/python/ocfweb/lib/python3.4/site-packages/ocfweb/caching.py", line 170, in function_with_timestamp
    return (datetime.now(), self.function())
  File "/usr/share/python/ocfweb/lib/python3.4/site-packages/ocfweb/stats/summary.py", line 68, in printers
    for printer in PRINTERS
  File "/usr/share/python/ocfweb/lib/python3.4/site-packages/ocfweb/stats/summary.py", line 68, in <genexpr>
    for printer in PRINTERS
  File "/usr/share/python/ocfweb/lib/python3.4/site-packages/ocflib/lab/printing.py", line 40, in get_toner
    for oid in (OID_TONER_CUR, OID_TONER_MAX)
  File "/usr/share/python/ocfweb/lib/python3.4/site-packages/ocflib/lab/printing.py", line 40, in <genexpr>
    for oid in (OID_TONER_CUR, OID_TONER_MAX)
  File "/usr/share/python/ocfweb/lib/python3.4/site-packages/ocflib/lab/printing.py", line 30, in _snmp
    'Device {} returned error status: {}'.format(host, err_status),
OSError: Device deforestation returned error status: 5


Periodic function:
  * Key: ('2016.01.20.18.11-gitbf0aae55', 'ocfweb.stats.summary#printers', (), ())
  * Last Update: 2016-01-21 15:48:30.668738 (61.003647 seconds ago)


  * Period: 60
  * TTL: 120

The background process will now pause for 30 seconds.


====
Hostname: coma.ocf.berkeley.edu
Callstack:
    at /usr/share/python/ocfweb/lib/python3.4/site-packages/ocflib/misc/mail.py:59 (send_problem_report)
        by /usr/share/python/ocfweb/lib/python3.4/site-packages/ocfweb/bin/run_periodic_functions.py:73 (run_periodic_functions)
        by /usr/share/python/ocfweb/lib/python3.4/site-packages/ocfweb/bin/run_periodic_functions.py:116 (main)
        by /usr/share/python/ocfweb/bin/ocfweb-run-periodic-functions:9 (<module>)
```



Discussion:

Resolving patch:
diff --git a/ocfweb/stats/summary.py b/ocfweb/stats/summary.py
--- a/ocfweb/stats/summary.py
+++ b/ocfweb/stats/summary.py
@@ -1,3 +1,4 @@
+import logging
 from datetime import date
 from datetime import datetime
 from operator import attrgetter
@@ -19,6 +20,9 @@
 from ocfweb.stats.daily_graph import get_open_close
 
 
+_logger = logging.getLogger(__name__)
+
+
 @periodic(60)
 def desktop_profiles():
     open_, close = get_open_close(date.today())
@@ -63,8 +67,17 @@ def users_in_lab_count():
 
 @periodic(60)
 def printers():
+    def silence(f):
+        def inner(*args, **kwargs):
+            try:
+                return f(*args, **kwargs)
+            except OSError as ex:
+                _logger.warn('Silencing exception reading printer data: {}'.format(ex))
+                return None
+        return inner
+
     return sorted(
-        (printer, get_toner(printer), get_maintkit(printer))
+        (printer, silence(get_toner)(printer), silence(get_maintkit)(printer))
         for printer in PRINTERS
     )
 


Test patch: