OSDN Git Service

Add watch window (#13)
authorkeisuke fukawa <keisuke@karesansui-project.info>
Tue, 27 Apr 2010 08:06:36 +0000 (17:06 +0900)
committerkeisuke fukawa <keisuke@karesansui-project.info>
Tue, 27 Apr 2010 08:06:36 +0000 (17:06 +0900)
 * add watch edit method

karesansui/gadget/hostby1watchby1.py
karesansui/templates/default/hostby1watchby1/hostby1watchby1.input

index 9e5a973..18a8912 100644 (file)
@@ -22,30 +22,22 @@ from karesansui.lib.checker import Checker, \
     CHECK_LENGTH, CHECK_MIN, CHECK_MAX
 
 from karesansui.db.access.watch import \
-    findbyall as w_findbyall, findby1 as w_findby1, \
-    findby1name as w_findby1name, findbyand as w_findbyand, \
-    new as w_new, save as w_save, \
-    logical_delete as w_delete
+    findby1 as w_findby1, \
+    logical_delete as w_delete, \
+    update as w_update
 
 from karesansui.db.access.machine import \
-     findby1 as m_findby1, findbyhost1 as m_findbyhost1
+    findbyhost1 as m_findbyhost1
 
-from karesansui.lib.utils import is_param, get_karesansui_version
+from karesansui.lib.utils import is_param
 
 from karesansui.lib.collectd.utils import plugin_selector_to_dict, \
-     threshold_value_to_dict
+    create_threshold_value, threshold_value_to_dict
 
-from karesansui.lib.const import WATCH_LIST_RANGE, \
-    COLLECTD_PLUGIN_CPU, COLLECTD_PLUGIN_DF, \
+from karesansui.lib.const import COLLECTD_PLUGIN_CPU, COLLECTD_PLUGIN_DF, \
     COLLECTD_PLUGIN_DISK, COLLECTD_PLUGIN_INTERFACE, COLLECTD_PLUGIN_LIBVIRT, \
     COLLECTD_PLUGIN_MEMORY, COLLECTD_PLUGIN_UPTIME, COLLECTD_PLUGIN_LOAD, \
-    COLLECTD_PLUGIN_USERS, COLLECTD_CPU_TYPE_INSTANCE, \
-    COLLECTD_MEMORY_TYPE_INSTANCE, COLLECTD_DF_DS, COLLECTD_DISK_TYPE, \
-    COLLECTD_DISK_DS, COLLECTD_INTERFACE_TYPE, COLLECTD_INTERFACE_DS, \
-    COLLECTD_CPU_TYPE, COLLECTD_MEMORY_TYPE, COLLECTD_DF_TYPE, \
-    COLLECTD_UPTIME_TYPE, COLLECTD_LIBVIRT_TYPE, \
-    COLLECTD_CPU_DS, COLLECTD_MEMORY_DS, COLLECTD_UPTIME_DS
-
+    COLLECTD_PLUGIN_USERS, COLLECTD_LIBVIRT_TYPE
 
 from karesansui.lib.collectd.config import delete_threshold
 from karesansui.lib.conf import read_conf, write_conf
@@ -116,6 +108,85 @@ class HostBy1WatchBy1(Rest):
         host_id = self.chk_hostby1(param)
         if host_id is None: return web.notfound()
 
+        watch_id = param[1]
+        if watch_id is None: return web.notfound()
+
+        if not validates_watch(self):
+            return web.badrequest(self.view.alert)
+
+        watch = w_findby1(self.orm, watch_id)
+
+        ## text
+        watch.name               = self.input.watch_name
+        watch.continuation_count = self.input.continuation_count
+        watch.prohibition_period = self.input.prohibition_period
+        watch.warning_script     = self.input.warning_script
+        watch.warning_mail_body  = self.input.warning_mail_body
+        watch.failure_script     = self.input.failure_script
+        watch.failure_mail_body  = self.input.failure_mail_body
+        watch.okay_script        = self.input.okay_script
+        watch.okay_mail_body     = self.input.okay_mail_body
+        watch.notify_mail_mta    = self.input.notify_mail_mta
+        watch.notify_mail_to     = self.input.notify_mail_to
+        watch.notify_mail_from   = self.input.notify_mail_from
+
+        warning_threshold   = self.input.warning_threshold
+        failure_threshold   = self.input.failure_threshold
+        watch.warning_value = create_threshold_value(min_value=None, max_value=warning_threshold)
+        watch.failure_value = create_threshold_value(min_value=None, max_value=failure_threshold)
+
+        ## bool
+        bool_input_key = ["use_percentage", "enable_warning_mail",
+                          "enable_failure_mail", "enable_okay_mail",
+                          "enable_warning_script", "enable_failure_script",
+                          "enable_okay_script"]
+        bool_values = {}
+        for key in bool_input_key:
+            if self.input.has_key(key):
+                bool_values.update({key:True})
+            else:
+                bool_values.update({key:False})
+
+        watch.is_warning_percentage = bool_values.get("use_percentage")
+        watch.is_warning_script     = bool_values.get("enable_warning_script")
+        watch.is_warning_mail       = bool_values.get("enable_warning_mail")
+        watch.is_failure_percentage = bool_values.get("use_percentage")
+        watch.is_failure_script     = bool_values.get("enable_failure_script")
+        watch.is_failure_mail       = bool_values.get("enable_failure_mail")
+        watch.is_okay_script        = bool_values.get("enable_okay_script")
+        watch.is_okay_mail          = bool_values.get("enable_okay_mail")
+
+        w_update(self.orm, watch)
+
+
+        """
+        #import pdb;pdb.set_trace()
+        modules = ["collectdplugin"]
+
+        host = m_findbyhost1(self.orm, host_id)
+        extra_args = {'include':'^threshold_'}
+        #extra_args = {}
+        dop = read_conf(modules, webobj=self, machine=host, extra_args=extra_args)
+        if dop is False:
+            return web.internalerror('Internal Server Error. (Timeout)')
+
+        # スレッショルドの作成
+        params = {}
+        params['WarningMax'] = str(warning_threshold)
+        params['FailureMax'] = str(failure_threshold)
+        params['Percentage'] = str(bool_values.get("use_percentage")).lower()
+        params['Persist']    = "true"
+        params['Message']    =  "\"name:%{ds:name} val:%{ds:value} fmin:%{failure_min} fmax:%{failure_max} wmin:%{warning_min} wmax:%{warning_max}\""
+        set_threshold(plugin,plugin_selector,params,dop=dop,webobj=self, host=host)
+
+        extra_args = {}
+        command = "/etc/init.d/hde-collectd condrestart"
+        extra_args = {"post-command": command}
+        retval = write_conf(dop,  webobj=self, machine=host, extra_args=extra_args)
+        if retval is False:
+            return web.internalerror('Internal Server Error. (Adding Task)')
+        """
+
         return web.accepted()
 
     @auth
index cf17099..89f38f9 100644 (file)
@@ -55,7 +55,7 @@ function set_slider(id, min, max, default_val1, default_val2) {
 
 $(document).ready(function(){
 
-    ajax_post_event(
+    ajax_put_event(
         "#edit_watch_button",
         "${ctx.homepath}${ctx.path}",
         "#watch_setting :input",