Joe Heck avatar Joe Heck committed b1f24ed

twiddling the views up - jQuery work

Comments (0)

Files changed (3)

eyeswebapp/core/views.py

     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
+    plugin_name = forms.ChoiceField(choices=plugin_choices)  # names of nagios plugins - like check_snmp
+    # normally set , initial="check_ping" for the plugin_name
+    # but avoiding it due to rendering bug in jQueryMobile 1.0a2
+    argument = forms.CharField()  # string argument...
+    alerting = forms.BooleanField(initial=True, required=False)
+    passive = forms.BooleanField(initial=False, required=False)  # identifies a passive monitor
     host = forms.ModelChoiceField(queryset=host_queryset, empty_label="(No Host)")
 
     # if request.method == 'POST': # If the form has been submitted...
 
 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()
     form = NewMonitorForm()
+    if request.method == 'POST': # If the form has been submitted...
+        form = NewMonitorForm(request.POST) # A form bound to the POST data
+        if form.is_valid():
+            print "Starting..."
+            new_monitor = Monitor()
+            new_monitor.host = form.cleaned_data['host']
+            new_monitor.name = form.cleaned_data['name']
+            new_monitor.alerting = form.cleaned_data['alerting']
+            new_monitor.passive = form.cleaned_data['passive']
+            new_monitor.plugin_name = form.cleaned_data['plugin_name']
+            print "created the newmonitor..."
+            argset = ArgSet()
+            a_string = form.cleaned_data['argument']
+            import simplejson
+            print a_string
+            print a_string.__class__
+            foo = simplejson.loads(a_string)
+            #argset.loadjson(str(form.cleaned_data['argument']))
+            # for string_arg in request.POST.getlist('argument'):
+            #     argset.add_argument(string_arg)
+            new_monitor.arg_set = argset
+            print "saving..."
+            new_monitor.save()
+            print new_monitor
     return render_response(request, 'core/monitor_list.html', {'monitor_list': monitor_list, 'form': form})
 
 

eyeswebapp/settings.py

 
 INTERNAL_IPS = ('127.0.0.1',)
 
-DEFAULT_FROM_EMAIL = 'alert@yourhost.com'
+SERVER_EMAIL = 'alerts@somewhere.com'
+DEFAULT_FROM_EMAIL = 'alerts@somewhere.com'
 DEFAULT_CHARSET = "utf-8"
 EMAIL_HOST = 'localhost'
 EMAIL_PORT = 25

eyeswebapp/templates/core/monitor_list.html

 {% block content-header %}Eyes{% endblock %}
 
 {% block content %}
+
+<script type="text/javascript">
+$(document).ready(function() {
+
+	$("#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 = $("#id_plugin_name").val()
+		$.post("/core/ajax_monitor/"+plugin_name+"/",
+			$("#id_argument").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>
+
+
 {% 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>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.