Commits

Joe Heck committed 787a040

adding new form to create monitor from scratch

  • Participants
  • Parent commits 5530afa

Comments (0)

Files changed (3)

 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?)
+* edit a monitor... (done: 279:5530afa8cdc0)
 * 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

File eyeswebapp/core/views.py

 from django.shortcuts import render_to_response, get_object_or_404
 from django.template import RequestContext
 
+from django import forms
 from django.forms import ModelForm
 
 import os
     class Meta:
         model = Monitor
 
+class NewMonitorForm(forms.Form):
+    plugin_list = NagiosPoller().plugin_list()
+    plugin_choices = []
+    for plugin_name in plugin_list:
+        plugin_choices.append((plugin_name, plugin_name,))
+    host_queryset = Host.objects.all()
+    
+    name = forms.CharField(max_length=250)  # user specified name
+    plugin_name = forms.ChoiceField(choices=plugin_choices, initial="check_ping")  # names of nagios plugins - like check_snmp
+    json_argset = forms.CharField()  # json representation of an ArgSet
+    alerting = forms.BooleanField(initial=True)
+    passive = forms.BooleanField(initial=False)  # identifies a passive monitor
+    host = forms.ModelChoiceField(queryset=host_queryset, empty_label="(No Host)")
 
 def render_response(req, *args, **kwargs):
     """ a variation on render_to_response that inserts the RequestContext
 def monitor_detail(request, monitor_id):
     """ detail view of the individual monitor"""
     mon = get_object_or_404(Monitor, pk=monitor_id)
-    
     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})
+    return render_response(request, 'core/monitor_detail.html', {'monitor': mon, 'form': form,})
 
 
 def datastore_detail(request, datastore_id):
     #     user.set_password('admin')
     #     user.put()
     monitor_list = Monitor.objects.all()
-    return render_response(request, 'core/monitor_list.html', {'monitor_list': monitor_list})
+    form = NewMonitorForm()
+    return render_response(request, 'core/monitor_list.html', {'monitor_list': monitor_list, 'form': form})
 
 
 def plugin_list(request):

File eyeswebapp/templates/core/monitor_list.html

 	{% endfor %}
 </ul>{% endif %}
 
-<form><div data-role="fieldcontain">
-    <label for="search">Search Input:</label>
-    <input type="search" name="password" id="search" value="" />
-</div></form>
+{% if form %}<div data-role="collapsible" data-collapsed="true" data-theme="a">
+	<h3>New 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>{% endif %}
+
 {% endblock %}