Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2533617
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
7 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/test/nagios/caldav_connect.py b/test/nagios/caldav_connect.py
index 826b9c7..b094e9e 100755
--- a/test/nagios/caldav_connect.py
+++ b/test/nagios/caldav_connect.py
@@ -1,61 +1,61 @@
#!/usr/bin/python
#
# Copyright 2010-2013 Kolab Systems AG (http://www.kolabsys.com)
#
-# Thomas Bruderli (Kolab Systems) <bruederli@kolabsys.com>
+# Thomas Bruederli <bruederli@kolabsys.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 or, at your option, any later version
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
import sys
from dav_utils import *
from urllib import quote as urlencode
from httplib import HTTPException
PORPFIND_CALENDARS = "<?xml version='1.0' encoding='utf-8' ?><D:propfind xmlns:D='DAV:'><D:prop><D:displayname/><D:resourcetype/></D:prop></D:propfind>"
def main(args):
exit = EXIT_OK
if not test_http_auth(args):
exit = EXIT_CRITICAL
msg = "FATAL: HTTP Auth"
if exit == EXIT_OK and not test_propfind_cal(args):
exit = EXIT_WARNING
msg = "WARNING: PROPFIND to user calendars failed"
if exit is not EXIT_OK:
print >> sys.stderr, msg
sys.exit(exit)
def test_propfind_cal(args):
conn = get_connection(args)
ret = False
try:
headers = { "Content-Type": "text/xml", "Authorization": basic_auth(args) }
conn.request("PROPFIND", abs_path("/calendars/" + urlencode(args.user) + "/", args), PORPFIND_CALENDARS, headers)
res = conn.getresponse()
if res.status == 207 and check_header(res, "dav") and res.read().find('<d:multistatus'):
ret = True
except (HTTPException, Exception) as e:
print >> sys.stderr, str(e)
conn.close()
return ret
if __name__ == "__main__":
main(getopts())
diff --git a/test/nagios/carddav_connect.py b/test/nagios/carddav_connect.py
index dabb735..a45307a 100755
--- a/test/nagios/carddav_connect.py
+++ b/test/nagios/carddav_connect.py
@@ -1,61 +1,61 @@
#!/usr/bin/python
#
# Copyright 2010-2013 Kolab Systems AG (http://www.kolabsys.com)
#
-# Thomas Bruderli (Kolab Systems) <bruederli@kolabsys.com>
+# Thomas Bruederli <bruederli@kolabsys.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 or, at your option, any later version
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
import sys
from dav_utils import *
from urllib import quote as urlencode
from httplib import HTTPException
PORPFIND_ABOOKS = "<?xml version='1.0' encoding='utf-8' ?><D:propfind xmlns:D='DAV:'><D:prop><D:displayname/><D:resourcetype/></D:prop></D:propfind>"
def main(args):
exit = EXIT_OK
if not test_http_auth(args):
exit = EXIT_CRITICAL
msg = "FATAL: HTTP Auth"
if exit == EXIT_OK and not test_propfind_addr(args):
exit = EXIT_WARNING
msg = "WARNING: PROPFIND to user calendars failed"
if exit is not EXIT_OK:
print >> sys.stderr, msg
sys.exit(exit)
def test_propfind_addr(args):
conn = get_connection(args)
ret = False
try:
headers = { "Content-Type": "text/xml", "Authorization": basic_auth(args) }
conn.request("PROPFIND", abs_path("/addressbooks/" + urlencode(args.user) + "/", args), PORPFIND_ABOOKS, headers)
res = conn.getresponse()
if res.status == 207 and check_header(res, "dav") and res.read().find('<d:multistatus'):
ret = True
except (HTTPException, Exception) as e:
print >> sys.stderr, str(e)
conn.close()
return ret
if __name__ == "__main__":
main(getopts())
diff --git a/test/nagios/dav_utils.py b/test/nagios/dav_utils.py
index c907ff2..2a08382 100644
--- a/test/nagios/dav_utils.py
+++ b/test/nagios/dav_utils.py
@@ -1,62 +1,82 @@
+# Utility functions to be used in CalDAV/CardDAV nagios scripts
+#
+# Copyright 2010-2013 Kolab Systems AG (http://www.kolabsys.com)
+#
+# Thomas Bruederli <bruederli@kolabsys.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 3 or, at your option, any later version
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Library General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+
import sys, argparse
from base64 import b64encode
from httplib import HTTPConnection, HTTPSConnection
# nagios return codes
EXIT_OK = 0
EXIT_WARNING = 1
EXIT_CRITICAL = 2
PORPFIND_PRINCIPAL = "<?xml version='1.0' encoding='utf-8' ?><D:propfind xmlns:D='DAV:'><D:prop><D:principal-collection-set/></D:prop></D:propfind>"
def getopts():
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--server', dest='server', required=True)
parser.add_argument('-u', '--user', dest='user', required=True)
parser.add_argument('-p', '--pass', dest='passwd', required=True)
parser.add_argument('-d', '--dir', dest='dir')
return parser.parse_args()
def get_connection(args):
if args.server.find("https") == 0:
conn = HTTPSConnection(re.sub(r'^https://', r'', args.server))
else:
conn = HTTPConnection(args.server)
return conn
def check_header(res, hdr):
for h,v in res.getheaders():
if h == hdr:
return v
return None
def basic_auth(args):
return "Basic " + b64encode(args.user + ":" + args.passwd)
def abs_path(path, args):
base = args.dir.rstrip('/') if args.dir else ''
return base + path
def test_http_auth(args):
conn = get_connection(args)
ret = False
try:
# check unauthenticated response
headers = { "Content-Type": "text/xml" }
conn.request("PROPFIND", abs_path("/", args), PORPFIND_PRINCIPAL, headers)
res = conn.getresponse()
if res.status == 401 and check_header(res, "www-authenticate") and res.read().find('<d:error'):
# check user authentication
headers = { "Content-Type": "text/xml", "Authorization": basic_auth(args) }
conn.request("PROPFIND", abs_path("/", args), PORPFIND_PRINCIPAL, headers)
res = conn.getresponse()
if res.status == 207 and check_header(res, "dav"):
ret = True
except (HTTPException, Exception) as e:
print >> sys.stderr, str(e)
conn.close()
return ret
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Feb 5, 7:16 PM (3 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
427993
Default Alt Text
(7 KB)
Attached To
Mode
R5 irony
Attached
Detach File
Event Timeline
Log In to Comment