]> gitweb.michael.orlitzky.com - untangle-https-backup.git/blobdiff - bin/untangle-https-backup
bin/untangle-https-backup: expect and report socket timeouts.
[untangle-https-backup.git] / bin / untangle-https-backup
index dab5c1807bb8e9c712c34d0a184df270f93a15e9..25fbf9d2364a7b94242a3f9b540b8589f658c3f6 100755 (executable)
@@ -5,8 +5,10 @@ Back up Untangle configurations via the web admin UI.
 
 from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
 import configparser
+from http.client import HTTPException
 from os import chmod
 from urllib.error import HTTPError, URLError
+from socket import timeout
 from sys import stderr
 
 from untangle.untangle import Untangle
@@ -53,11 +55,28 @@ for section in config.sections():
     # If it didn't work, but in a predictable way (some host is down),
     # then we report that error and keep going.
     except URLError as e:
-        msg =  u.name + ': ' + str(e.reason) + ' from ' + u.host
+        tpl = '{:s}: {:s} from {:s}'
+        msg = tpl.format(u.name, str(e.reason), u.host)
         print(msg, file=stderr)
         status = EXIT_BACKUPS_FAILED
     except HTTPError as e:
-        msg =  u.name + ': ' + 'HTTP error ' + str(e.code) + ' from ' + u.host
+        tpl = '{:s}: HTTP error {:s} from {:s}'
+        msg = tpl.format(u.name, str(e.code), u.host)
+        print(msg, file=stderr)
+        status = EXIT_BACKUPS_FAILED
+    except HTTPException as e:
+        # At least one sort of HTTPException (BadStatusLine) is not
+        # translated by urllib into an HTTPError, so we catch
+        # HTTPExceptions too.
+        tpl = '{:s}: HTTP exception {:s} from {:s}'
+        msg = tpl.format(u.name, repr(e), u.host)
+        print(msg, file=stderr)
+        status = EXIT_BACKUPS_FAILED
+    except timeout as e:
+        # A socket.timeout exception occurs when something goes over
+        # the configured "timeout" limit.
+        tpl = '{:s}: socket timeout ({:s}) from {:s}'
+        msg = tpl.format(u.name, str(e), u.host)
         print(msg, file=stderr)
         status = EXIT_BACKUPS_FAILED