From 5c4d52666088d6817fa5825afa4f17ef9440ee44 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Thu, 12 Jul 2018 22:31:50 +0200 Subject: [PATCH] Align Sahana files with upstream --- .../srv/sahana-demo/conf/000_config.py | 3 - sahana/srv/sahana/conf/000_config.py | 3 - sahana/srv/sahana/data/Spotter/config.py | 24 ++- sahana/srv/sahana/data/Spotter/css.cfg | 5 +- .../srv/sahana/data/Spotter/gis_hierarchy.csv | 32 +++- sahana/srv/sahana/data/Spotter/monitor.py | 148 ++++++++++++++++++ sambro/srv/sambro/conf/000_config.py | 3 - 7 files changed, 203 insertions(+), 15 deletions(-) create mode 100644 sahana/srv/sahana/data/Spotter/monitor.py diff --git a/sahana-demo/srv/sahana-demo/conf/000_config.py b/sahana-demo/srv/sahana-demo/conf/000_config.py index 86c95b6..57fc322 100644 --- a/sahana-demo/srv/sahana-demo/conf/000_config.py +++ b/sahana-demo/srv/sahana-demo/conf/000_config.py @@ -130,9 +130,6 @@ settings.frontpage.rss = [ # Uncomment to enable a guided tour #settings.base.guided_tour = True -# Instance Name - for management scripts -#settings.base.instance_name = "test" - # Bing API Key (for Map layers) # http://www.microsoft.com/maps/create-a-bing-maps-key.aspx #settings.gis.api_bing = "" diff --git a/sahana/srv/sahana/conf/000_config.py b/sahana/srv/sahana/conf/000_config.py index efc4374..aadae4c 100644 --- a/sahana/srv/sahana/conf/000_config.py +++ b/sahana/srv/sahana/conf/000_config.py @@ -130,9 +130,6 @@ settings.frontpage.rss = [ # Uncomment to enable a guided tour #settings.base.guided_tour = True -# Instance Name - for management scripts -#settings.base.instance_name = "test" - # Bing API Key (for Map layers) # http://www.microsoft.com/maps/create-a-bing-maps-key.aspx #settings.gis.api_bing = "" diff --git a/sahana/srv/sahana/data/Spotter/config.py b/sahana/srv/sahana/data/Spotter/config.py index 673dae0..e11969f 100644 --- a/sahana/srv/sahana/data/Spotter/config.py +++ b/sahana/srv/sahana/data/Spotter/config.py @@ -58,6 +58,8 @@ def config(settings): settings.auth.registration_requests_organisation = True # Uncomment this to have the Organisation selection during registration be mandatory settings.auth.registration_organisation_required = True + # Uncomment this to hide the Create-Organisation link in registration forms + #settings.auth.registration_organisation_link_create = False # Uncomment this to have the Organisation input hidden unless the user enters a non-whitelisted domain #settings.auth.registration_organisation_hidden = True # Uncomment this to default the Organisation during registration @@ -417,6 +419,11 @@ def config(settings): # Uncomment to modify the main menu logo #settings.ui.menu_logo = URL(c="static", f="img", args=["S3menulogo.png"]) + # ------------------------------------------------------------------------- + # Sync + # Uncomment if this deployment exposes public data sets + settings.sync.data_repository = True + # ------------------------------------------------------------------------- # Asset # Uncomment to have a specific asset type for Telephones @@ -528,6 +535,8 @@ def config(settings): # Events # Uncomment to use the term Disaster instead of Event #settings.event.label = "Disaster" + # Uncomment to not use Incidents under Events + #settings.event.incident = False # Uncomment to preserve linked Incidents when an Event is deleted # NB Changing this setting requires a DB migration #settings.event.cascade_delete_incidents = False @@ -592,6 +601,8 @@ def config(settings): #settings.org.autocomplete = True # Enable the Organisation Sector field settings.org.sector = True + # But hide it from the rheader + #settings.org.sector_rheader = False # Enable the use of Organisation Branches settings.org.branches = True # Show branches as tree rather than as table @@ -607,6 +618,8 @@ def config(settings): settings.org.organisation_types_hierarchical = True # Make Organisation Types Multiple settings.org.organisation_types_multiple = True + # Show Organisation Types in the rheader + settings.org.organisation_type_rheader = True # Enable the use of Organisation Regions settings.org.regions = True # Make Organisation Regions Hierarchical @@ -877,9 +890,12 @@ def config(settings): # ------------------------------------------------------------------------- # Supply + # Name of the Default Item Catalog. Do not edit after deployment + #settings.supply.catalog_default = "Default" + # Disable the use of Multiple Item Catalogs + #settings.supply.catalog_multi = False + # Disable the use of Alternative Items #settings.supply.use_alt_name = False - # Do not edit after deployment - #settings.supply.catalog_default = T("Default") # ------------------------------------------------------------------------- # Projects @@ -899,6 +915,10 @@ def config(settings): settings.project.activity_types = True # Uncomment this to filter dates in Activities #settings.project.activity_filter_year = True + # Uncomment this to not use Beneficiaries for Activities + #settings.project.get_project_activity_beneficiaries = False + # Uncomment this to not use Item Catalog for Distributions + #settings.project.activity_items = False # Uncomment this to use Codes for projects #settings.project.codes = True # Uncomment this to call project locations 'Communities' diff --git a/sahana/srv/sahana/data/Spotter/css.cfg b/sahana/srv/sahana/data/Spotter/css.cfg index 89ab276..9776edc 100644 --- a/sahana/srv/sahana/data/Spotter/css.cfg +++ b/sahana/srv/sahana/data/Spotter/css.cfg @@ -42,5 +42,6 @@ d3/nv.d3.css ../themes/default/report.css ../themes/default/survey.css ../themes/default/newsfeed.css -../themes/default/style.css -# Final line required for parsing \ No newline at end of file +../themes/default/theme.css +#../themes/default/style.css +# Final line required for parsing diff --git a/sahana/srv/sahana/data/Spotter/gis_hierarchy.csv b/sahana/srv/sahana/data/Spotter/gis_hierarchy.csv index ba9c6c3..4503978 100644 --- a/sahana/srv/sahana/data/Spotter/gis_hierarchy.csv +++ b/sahana/srv/sahana/data/Spotter/gis_hierarchy.csv @@ -3,6 +3,7 @@ SITE_DEFAULT,,"State / Province","County / District","City / Town / Village","Vi ,AF,Province,District,Village,,, ,AL,County,District,Municipality,,, ,AM,Province,Community,Settlement,,, +,AR,Province,Department,Municipality, ,AS,District,County,Village,,, ,AT,State,"District / City",Municipality, ,AU,"State / Territory",Local Government Area,,,, @@ -12,52 +13,79 @@ SITE_DEFAULT,,"State / Province","County / District","City / Town / Village","Vi ,BE,Region,Province,Arrondissement,Commune, ,BG,Province,Municipality,,, ,BI,Province,Commune,Colline,Sous Colline, +,BN,District,Mukim,, +,BO,Department,Province,Municipality,Canton +,BR,State,Municipality,District,, +,BT,District,Sub-District,, +,BZ,District,,, ,CF,Prefecture,Sub-Prefecture,Commune,, +,CK,Island Council,Village Committee,,, +,CL,Region,Province,Commune,, ,CM,Region,Division,Sub-Division,Village, +,CO,Department,Municipality,Corregimiento, +,CR,Province,Canton,District, +,CU,Province,Municipality, ,DE,"Federal State","Rural District / District","Town / Municipality",Village, +,DO,Province,Municipality,,,, ,EC,Province,Canton,Parish,,, ,FI,Regional State Administrative Agency,Region,Sub-region,Municipality,, ,FJ,Division,Province,District,,,, ,GE,"Region / Republic",District,,,, ,GN,Region,Prefecture,Sub-prefecture,,, ,GR,Decentralized Administration,Region,Regional Unit,Municipality,, +,GT,Department,Municipality, ,HN,Department,Municipality,Village,,, ,HR,County,"Town / Municipality",,,, +,HT,Department,Commune,Communal section,, ,HU,County,District,,,, ,ID,Province,"Regency / City",District,Administrative Village,, -,IN,State,District,Subdistrict,,, +,IN,State,District,Sub-District,,, ,IQ,Province,District,,,, ,IT,Region,Province,Commune,,, ,KE,County,Constituency,Location,SubLocation, ,KG,"Oblast / State City","District (Rayon) / Oblast City","Town / Village Group",Village,, ,KH,Province,District,Commune,Village, +,KI,Island Council,,,, ,KZ,Province,District,,,, +,LA,Province,District,Village,,, ,LK,Province,District,Divisional Secretariat,Grama Niladhari,, ,LR,County,District,Clan,,, +,LT,County,Municipality,Eldership,,, ,LY,District,"City / Town / Village",,,, ,MG,Region,District,Commune,Fokontany, ,MK,Municipality,,,, ,MM,State,District,Township,Village Tract,Village, -,MN,Province,District,Subdistrict,,, +,MN,Province,District,Sub-District,,, ,MP,Municipality,Village,,,, ,MV,"Atoll/City",Island,,,, +,MX,State,Municipality, ,MY,State,District,Mukim,,, +,NI,Department,Municipality, ,NP,Region,Zone,District,Village Development Committee,Ward, ,NZ,Region,Territorial Authority,,,, +,PA,Province,District,Corregimiento,, +,PE,Region,Province,District,, ,PG,Province,District,LLG,Village,, ,PH,Region,Province,"City / Municipality",Barangay,, ,PK,Province,District,Tehsil,Union Council,Village, ,PY,Department,District,"City / Town / Village",,, ,RS,District,"Municipality / City",,,, +,SB,Province,Ward,, ,SE,County,Municipality,,,, +,SG,Region,,, ,SL,Province,District,Chiefdom,,, +,SV,Department,Municipality, ,TD,Region,Department,Sub-Prefecture,Canton, +,TH,Province,District,Sub-District,,, ,TJ,Province,District,Jamoat,Village,, ,TL,District,SubDistrict,Suco,Aldeia,, ,TM,Province,District,,,, +,TO,Island Group,District,,,, ,TR,City,Town,District,,, +,TV,Island Council,,,, ,PR,Municipality,Barrio,,,, ,US,State,County,City,Neighborhood,,False ,UZ,Province,District,,,, +,VU,Province,Area Council,, ,VN,Province,District,Commune,,, ,XK,District,Municipality,,,, diff --git a/sahana/srv/sahana/data/Spotter/monitor.py b/sahana/srv/sahana/data/Spotter/monitor.py new file mode 100644 index 0000000..686afe8 --- /dev/null +++ b/sahana/srv/sahana/data/Spotter/monitor.py @@ -0,0 +1,148 @@ +# -*- coding: utf-8 -*- +# vim: ai ts=4 sts=4 et sw=4 encoding=utf-8 + +""" Monitoring + + Template-specific Monitoring Tasks are defined here. + + @copyright: 2014-2018 (c) Sahana Software Foundation + @license: MIT + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following + conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. +""" + +__all__ = ("S3Monitor",) + +import datetime +import platform +import subprocess + +from gluon import current +#from gluon.tools import fetch + +# ============================================================================= +class S3Monitor(object): + """ + Monitoring Check Scripts + """ + + # ------------------------------------------------------------------------- + @staticmethod + def ping(task_id, run_id): + """ + Ping a server + """ + + s3db = current.s3db + + # Read the IP to Ping + ttable = s3db.setup_monitor_task + stable = s3db.setup_server + query = (ttable.id == task_id) & \ + (ttable.server_id == stable.id) + row = current.db(query).select(stable.host_ip, + limitby = (0, 1) + ).first() + + host_ip = row.host_ip + + try: + output = subprocess.check_output("ping -{} 1 {}".format("n" if platform.system().lower == "windows" else "c", host_ip), shell=True) + except Exception, e: + # Critical: Ping failed + return 3 + else: + # OK + return 1 + + # ------------------------------------------------------------------------- + #@staticmethod + #def http(task_id, run_id): + # """ + # Test that HTTP is accessible + # """ + + # ------------------------------------------------------------------------- + #@staticmethod + #def https(task_id, run_id): + # """ + # Test that HTTPS is accessible + # @ToDo: Check that SSL certificate hasn't expired + # """ + + # ------------------------------------------------------------------------- + @staticmethod + def email_round_trip(task_id, run_id): + """ + Check that a Mailbox is being Polled & Parsed OK and can send replies + """ + + # Read the Task Options + otable = current.s3db.setup_monitor_task_option + query = (otable.task_id == task_id) & \ + (otable.deleted == False) + rows = current.db(query).select(otable.tag, + otable.value, + ) + options = dict((row.tag, row.value) for row in rows) + + to = options.get("to", None) + if not to: + return False + + subject = options.get("subject", "") + message = options.get("message", "") + reply_to = options.get("reply_to") + if not reply_to: + # Use the outbound email address + reply_to = current.deployment_settings.get_mail_sender() + if not reply_to: + return False + + # Append the run_id for the remote parser to identify as a monitoring message & return to us to be able to match the run + message = "%s\n%s" % (message, ":run_id:%s:" % run_id) + + # Append the reply_to address for the remote parser + message = "%s\n%s" % (message, ":reply_to:%s:" % reply_to) + + # Send the Email + result = current.msg.send_email(to, + subject, + message, + reply_to=reply_to) + + if result: + # Schedule a task to see if the reply has arrived after 1 hour + start_time = datetime.datetime.utcnow() + datetime.timedelta(hours=1) + current.s3task.schedule_task("setup_monitor_check_email_reply", + args = [run_id], + start_time = start_time, + timeout = 300, # seconds + repeats = 1 # one-time + ) + # Warning: No reply received yet + return 2 + else: + # Critical: Unable to send Email + return 3 + +# END ========================================================================= diff --git a/sambro/srv/sambro/conf/000_config.py b/sambro/srv/sambro/conf/000_config.py index 1f2b1ca..0efe87c 100644 --- a/sambro/srv/sambro/conf/000_config.py +++ b/sambro/srv/sambro/conf/000_config.py @@ -130,9 +130,6 @@ settings.frontpage.rss = [ # Uncomment to enable a guided tour #settings.base.guided_tour = True -# Instance Name - for management scripts -#settings.base.instance_name = "test" - # Bing API Key (for Map layers) # http://www.microsoft.com/maps/create-a-bing-maps-key.aspx #settings.gis.api_bing = ""