Skip to content

Commit

Permalink
First version of monitor code
Browse files Browse the repository at this point in the history
  • Loading branch information
sthapa committed May 14, 2014
1 parent 420432d commit dc05360
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 1 deletion.
4 changes: 3 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Copyright 2014 University of Chicago

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down Expand Up @@ -198,4 +200,4 @@ Apache License
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
limitations under the License.
73 changes: 73 additions & 0 deletions check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python

import hashlib

import jinja2
import requests
import paramiko

def test_login(test_name, host, user ):
reponse = [test_name, "OK", ""]
client = paramiko.client.SSHClient()
try:
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname=host, port=22, username=user)
except paramiko.AuthenticationException:
response = (test_name, "FAILED", "Can't authenticate to %s" % host)
except paramiko.SSHException:
response = (test_name, "FAILED", "Can't establish ssh connection to %s" % host)
except socket.error:
response = (test_name, "FAILED", "Socket error connecting to %s" % host)
return response

def test_download(test_name, url, sha1):
response = [test_name, "OK", error]
try:
r = requests.get(url, timeout=60)
if r.status_code != requests.codes.ok:
response[1] = "FAILED"
response[2] = "HTTP Status code: %s" % r.status_code
return response
if hashlib.sha1(r.text) != sha1:
response = (test_name, "FAILED", "File content doesn't match")
except requests.exceptions.Timeout:
response[1] = "FAILED"
response[2] = "Connection to server timed out"
except requests.exceptions.ConnectionError:
response[1] = "FAILED"
response[2] = "Connection error"
except requests.exceptions.HTTPError:
response[1] = "FAILED"
response[2] = "Invalid HTTP Response"
except requests.exceptions:
response[1] = "FAILED"
response[2] = "Invalid HTTP Response"

return response

def test_xroot(test_name, uri, sha1):
response = (test_name, "OK", error)

return response


def run_tests():
http_results = []
http_hosts = [['Stash HTTP test',
'http://stash.osgconnect.net/keys/cern.ch.pub',
'sha1']]
ssh_results = []
ssh_hosts = [['OSG Connect login', 'login.osgconnect.net', 'sthapa']]
#xrdcp_hosts = [['FAXBOX', 'xrootd://faxbox.atlasconnect.net', 'sha1']]
for host in http_hosts:
http_results.append(test_download(*host))
for host in ssh_hosts:
ssh_results.append(test_login(*host))
env = jinja2.Environment(loader=jinja2.FileSystemLoader( searchpath="." ))
template = env.get_template('templates/check_page.html')
print template.render(http_results = http_results,
ssh_results = ssh_results,
xrootd_results = [])
if __name__ = "main":
run_tests()
sys.exit(0)
120 changes: 120 additions & 0 deletions templates/status.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />

<title>{{ title }}</title>
<meta name="description" content="{{ description }}" />
</head>

<body>

<div id="content">

{% if http_results %}
<h2> HTTP Status </h2>
<table>
<thead>
<tr>
<td>Test Name</td>
<td>Status</td>
<td>Messages</td>
</tr>
</thead>
<tbody>
{% for result in http_results %}
<tr>
<td>
{{ result[0] }}
</td>
{% if result[1] == 'OK' %}
<td style="color:green">
OK
</td>
{% else %}
<td style="color:red">
DOWN
</td>
{% endif %}
{% if result[2] %}
<td> {{ result[2] }} </td>
{% else %}
<td> &nbsp; </td>
{% endif %}
{% endfor %}
</tbody>
</table>
{% endif %}
{% if ssh_results %}
<h2> SSH Status </h2>
<table>
<thead>
<tr>
<td>Test Name</td>
<td>Status</td>
<td>Messages</td>
</tr>
</thead>
<tbody>
{% for result in ssh_results %}
<tr>
<td>
{{ result[0] }}
</td>
{% if result[1] == 'OK' %}
<td style="color:green">
OK
</td>
{% else %}
<td style="color:red">
DOWN
</td>
{% endif %}
{% if result[2] %}
<td> {{ result[2] }} </td>
{% else %}
<td> &nbsp; </td>
{% endif %}
{% endfor %}
</tbody>
</table>
{% endif %}
{% if xrootd_results %}
<h2> XRootd Status </h2>
<table>
<thead>
<tr>
<td>Test Name</td>
<td>Status</td>
<td>Messages</td>
</tr>
</thead>
<tbody>
{% for result in xrootd_results %}
<tr>
<td>
{{ result[0] }}
</td>
{% if result[1] == 'OK' %}
<td style="color:green">
OK
</td>
{% else %}
<td style="color:red">
DOWN
</td>
{% endif %}
{% if result[2] %}
<td> {{ result[2] }} </td>
{% else %}
<td> &nbsp; </td>
{% endif %}
{% endfor %}
</tbody>
</table>
{% endif %}

</div>

</body>
</html>

0 comments on commit dc05360

Please sign in to comment.