Commits

Joe Heck committed 5530afa

enable basic (ugly) monitor editing

  • Participants
  • Parent commits ebbda80

Comments (0)

Files changed (8)

 * refactor the simplePoller to read and write using the new REST API's (done: 225:b8f32ae1ba0d)
 * document the process to create a virtual machine with all the elements to run an instance of eyes (done: 235:8ada3eb00c10)
 
-Interupt: refactor ArgSet to be simple list - single and double tuple entries is too complex. (done: 263:8e6c6f64e8fa)
 
 milestone 4
+Interupt: refactor ArgSet to be simple list - single and double tuple entries is too complex. (done: 263:8e6c6f64e8fa)
+* make method for poller/poster to report errors in submitting data (invalid poller arguments)
+* show errors reported from poller
+* edit a monitor...
+* identify if the poller is running, or has run in the past 5 minutes (design elements for this?)
+* Host page -> New Monitor -> Save Monitor to Host
 * finalize an initial site design and layout with basic use cases (done: 274:939691d00b31)
 * bolster and add on additional models to flesh out use cases
 ** create models to tie monitors to groups & users
 *** a host page with a list of all monitors - selectable to get trend detail in sidebar (done: 274:939691d00b31)
 *** editing page - same as above, but with historical data available as trend as well (mult datasources)
 ** come up with Eyes logo
-* make method for poller/poster to report errors in submitting data (invalid poller arguments)
-* show errors reported from poller
-* edit a monitor...
-* identify if the poller is running, or has run in the past 5 minutes (design elements for this?)
-* Host page -> New Monitor -> Save Monitor to Host
 
 
 milestone 5

File eyeswebapp/core/urls.py

     (r'^host/(\d+)/$', 'host_detail'),  # , name='host_detail'
     (r'^datastore/(\d+)/$', 'datastore_detail'),  # , name='datastore_detail'
     (r'^datastore/(\d+)/png$', 'datastore_image'),  # , name='datastore_image'
-    (r'^host_list/$', 'host_list'),  # shows list of monitoring plugins
+    (r'^host_list/$', 'host_list'),  # shows list of hosts
+    (r'^monitor_list/$', 'monitor_list'),  # shows list of monitoring plugins
     # ajax views
     (r'^ajax_monitor/(\w+)/$', 'ajax_monitor'),  # ajax view to invoke a monitor plugindirectly
     # test URLs

File eyeswebapp/core/views.py

     class Meta:
         model = Host
 
+
+class MonitorForm(ModelForm):
+    class Meta:
+        model = Monitor
+
+
 def render_response(req, *args, **kwargs):
     """ a variation on render_to_response that inserts the RequestContext
     into each template context from these views."""
     #         is_active=True, is_staff=True, is_superuser=True)
     #     user.set_password('admin')
     #     user.put()
-    monitor_list = Monitor.objects.all()
-    return render_response(request, 'core/index.html', {'monitor_list': monitor_list})
+    monitors_in_unknown = Monitor.objects.filter(latest_state=3)
+    monitors_in_error = Monitor.objects.filter(latest_state=2)
+    monitors_in_warning = Monitor.objects.filter(latest_state=1)
+    return render_response(request, 'core/monitor_list.html',
+        {
+        'monitors_in_unknown': monitors_in_unknown,
+        'monitors_in_error': monitors_in_error,
+        'monitors_in_warning': monitors_in_warning,
+        })
 
 
 def visual_test(request):
 def monitor_detail(request, monitor_id):
     """ detail view of the individual monitor"""
     mon = get_object_or_404(Monitor, pk=monitor_id)
-    return render_response(request, 'core/monitor_detail.html', {'monitor': mon})
+    
+    form = MonitorForm(instance=mon)
+    if request.method == 'POST':
+        form = MonitorForm(request.POST, instance=mon)
+        if form.is_valid():
+            form.save()
+    return render_response(request, 'core/monitor_detail.html', {'monitor': mon, 'form': form})
 
 
 def datastore_detail(request, datastore_id):
 
 
 def monitor_list(request):
+    """ default web view for the 'front page' of the web application. """
+    # user = User.get_by_key_name('admin')
+    # if not user or user.username != 'admin' or not (user.is_active and
+    #         user.is_staff and user.is_superuser and
+    #         user.check_password('admin')):
+    #     user = User(key_name='admin', username='admin',
+    #         email='admin@localhost', first_name='Boss', last_name='Admin',
+    #         is_active=True, is_staff=True, is_superuser=True)
+    #     user.set_password('admin')
+    #     user.put()
+    monitor_list = Monitor.objects.all()
+    return render_response(request, 'core/monitor_list.html', {'monitor_list': monitor_list})
+
+
+def plugin_list(request):
     nagios_based_poller = NagiosPoller()
     list_of_plugins = nagios_based_poller.plugin_list()
-    return render_response(request, 'core/monitor_list.html', {'plugin_list': list_of_plugins})
+    return render_response(request, 'core/plugin_list.html', {'plugin_list': list_of_plugins})
 
 
 def test_monitor(request, plugin_name):

File eyeswebapp/templates/base.html

 	    <div data-role="footer" id="footer">{% block footer %}
 			<div data-role="navbar">
 				<ul>
-					<li><a href="/core/" rel="external">Monitors</a></li>
+					<li><a href="/core/" rel="external">Alerts</a></li>
+					<li><a href="/core/monitor_list/" rel="external">Monitors</a></li>
 					<li><a href="/core/host_list/" rel="external">Hosts</a></li>
 					<li><a href="/core/monitor_list/" rel="external">New</a></li>
 					<li>{% if user.is_authenticated %}

File eyeswebapp/templates/core/index.html

-{% extends 'base.html' %}
-{% block title %}index page{% endblock %}
-
-{% block content-header %}Eyes{% endblock %}
-
-{% block content %}
-<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b">
-	<li data-role="list-divider">Monitors</li>
-	{% for monitor in monitor_list %}
-	  <li><a href="{{monitor.get_absolute_url}}">{{monitor}}</a></li>
-	{% endfor %}
-</ul>
-<form><div data-role="fieldcontain">
-    <label for="search">Search Input:</label>
-    <input type="search" name="password" id="search" value="" />
-</div></form>
-{% endblock %}

File eyeswebapp/templates/core/monitor_detail.html

 	<p><img src="{{ds.get_absolute_url}}png"></p>
 	{% endfor %}
 </div>
+
+<div data-role="collapsible" data-collapsed="true" data-theme="a">
+	<h3>Edit Monitor</h3>
+	<form method='POST' action=".">
+		{% for field in form %}
+		<div data-role="fieldcontain">
+			{{field.errors}}
+			{{field.label_tag}} {{field}}
+		</div>	
+		{% endfor %}
+		<div data-role="fieldcontain">
+			<input type="submit" value="Submit">
+		</div>
+	</form>
+</div>
+
 {% endblock %}

File eyeswebapp/templates/core/monitor_list.html

 {% extends 'base.html' %}
-{% load eyes_filters %}
+{% block title %}index page{% endblock %}
 
-{% block title %}monitor list{% endblock %}
-
-{% block pagetitle %}monitor list{% endblock %}
+{% block content-header %}Eyes{% endblock %}
 
 {% block content %}
+{% if monitors_in_error %}
+<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b">
+	<li data-role="list-divider">Monitors (ERROR)</li>
+	{% for monitor in monitors_in_error %}
+	  <li><a href="{{monitor.get_absolute_url}}">{{monitor}}</a></li>
+	{% endfor %}
+</ul>{% endif %}
 
-<script type="text/javascript">
-$(document).ready(function() {
+{% if monitors_in_warning %}
+<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b">
+	<li data-role="list-divider">Monitors (WARNING)</li>
+	{% for monitor in monitors_in_warning %}
+	  <li><a href="{{monitor.get_absolute_url}}">{{monitor}}</a></li>
+	{% endfor %}
+</ul>{% endif %}
 
-	$("#tryit").click(function() {
-		$.get("/core/ajax_monitor/{{plugin_name}}/", function(data) {
-			var monitor_result = $.parseJSON(data);
-			$("#monitor_output").html(monitor_result.output);
-	    });
-	});
+{% if monitors_in_unknown %}
+<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b">
+	<li data-role="list-divider">Monitors (UNKNOWN)</li>
+	{% for monitor in monitors_in_unknown %}
+	  <li><a href="{{monitor.get_absolute_url}}">{{monitor}}</a></li>
+	{% endfor %}
+</ul>{% endif %}
 
-	$("#help").click(function() {		
-		var plugin_name = $("#select-monitor-type").val()
-		// alert("/core/ajax_monitor/"+plugin_name+"/")
-		$.get("/core/ajax_monitor/"+plugin_name+"/", function(data) {
-			var monitor_result = $.parseJSON(data);
-			$("#monitor_help_result").html(monitor_result.output);
-	    });
-		// alert('done...')
-	})
+{% if monitor_list %}
+<ul data-role="listview" data-inset="true" data-theme="c" data-dividertheme="b">
+	<li data-role="list-divider">Monitors</li>
+	{% for monitor in monitor_list %}
+	  <li><a href="{{monitor.get_absolute_url}}">{{monitor}}</a></li>
+	{% endfor %}
+</ul>{% endif %}
 
-	$("#tryit").click(function() {		
-		var plugin_name = $("#select-monitor-type").val()
-		$.post("/core/ajax_monitor/"+plugin_name+"/",
-			$("#arguments").serialize(),
-			function(data) {
-				var monitor_result = $.parseJSON(data);
-				$("#try_command").html(monitor_result.command);
-				$("#try_error").html(monitor_result.error);
-				$("#try_output").html(monitor_result.output);
-			}
-		);
-	})
-
-});
-</script>
-
-	<h3>Monitor Plugins</h3>
-
-	<div data-role="fieldcontain">
-		<label for="select-monitor-type" class="select">Choose monitor:</label>
-		<select name="select-monitor-type" id="select-monitor-type">
-			{% for plugin_name in plugin_list %}
-			<option value="{{plugin_name}}">{{plugin_name}}</option>
-			{% endfor %}			
-		</select>
-	</div>
-
-	<div data-role="collapsible" data-collapsed="true" data-theme="b">
-		<h3>Help</h3>
-		<p><input type="button" data-icon="info" id="help" value="HELP"/></p>
-		<pre id="monitor_help_result">...</pre>
-	</div>
-	
-	<div data-role="collapsible" data-theme="b">
-		<h3>Test</h3>
-		<form id="arguments">
-			<div><input type="text" name="argument"/></div>
-			<div><input type="text" name="argument"/></div>
-			<div><input type="text" name="argument"/></div>
-			<div><input type="text" name="argument"/></div>
-			<div><input type="button" data-icon="info" id="tryit" value="TRY"/></div>
-		</form>
-		<pre id="try_command"></pre>
-		<pre id="try_error"></pre>
-		<pre id="try_output"></pre>
-	</div>
-
-	
+<form><div data-role="fieldcontain">
+    <label for="search">Search Input:</label>
+    <input type="search" name="password" id="search" value="" />
+</div></form>
 {% endblock %}

File eyeswebapp/templates/core/plugin_list.html

+{% extends 'base.html' %}
+{% load eyes_filters %}
+
+{% block title %}monitor list{% endblock %}
+
+{% block pagetitle %}monitor list{% endblock %}
+
+{% block content %}
+
+<script type="text/javascript">
+$(document).ready(function() {
+
+	$("#tryit").click(function() {
+		$.get("/core/ajax_monitor/{{plugin_name}}/", function(data) {
+			var monitor_result = $.parseJSON(data);
+			$("#monitor_output").html(monitor_result.output);
+	    });
+	});
+
+	$("#help").click(function() {		
+		var plugin_name = $("#select-monitor-type").val()
+		// alert("/core/ajax_monitor/"+plugin_name+"/")
+		$.get("/core/ajax_monitor/"+plugin_name+"/", function(data) {
+			var monitor_result = $.parseJSON(data);
+			$("#monitor_help_result").html(monitor_result.output);
+	    });
+		// alert('done...')
+	})
+
+	$("#tryit").click(function() {		
+		var plugin_name = $("#select-monitor-type").val()
+		$.post("/core/ajax_monitor/"+plugin_name+"/",
+			$("#arguments").serialize(),
+			function(data) {
+				var monitor_result = $.parseJSON(data);
+				$("#try_command").html(monitor_result.command);
+				$("#try_error").html(monitor_result.error);
+				$("#try_output").html(monitor_result.output);
+			}
+		);
+	})
+
+});
+</script>
+
+	<h3>Monitor Plugins</h3>
+
+	<div data-role="fieldcontain">
+		<label for="select-monitor-type" class="select">Choose monitor:</label>
+		<select name="select-monitor-type" id="select-monitor-type">
+			{% for plugin_name in plugin_list %}
+			<option value="{{plugin_name}}">{{plugin_name}}</option>
+			{% endfor %}			
+		</select>
+	</div>
+
+	<div data-role="collapsible" data-collapsed="true" data-theme="b">
+		<h3>Help</h3>
+		<p><input type="button" data-icon="info" id="help" value="HELP"/></p>
+		<pre id="monitor_help_result">...</pre>
+	</div>
+	
+	<div data-role="collapsible" data-theme="b">
+		<h3>Test</h3>
+		<form id="arguments">
+			<div><input type="text" name="argument"/></div>
+			<div><input type="text" name="argument"/></div>
+			<div><input type="text" name="argument"/></div>
+			<div><input type="text" name="argument"/></div>
+			<div><input type="button" data-icon="info" id="tryit" value="TRY"/></div>
+		</form>
+		<pre id="try_command"></pre>
+		<pre id="try_error"></pre>
+		<pre id="try_output"></pre>
+	</div>
+
+	
+{% endblock %}