src/common.c: Reimplement format_name for performance.
[collectd.git] / src / plugin.c
index 9d10631..809c140 100644 (file)
@@ -726,6 +726,9 @@ static int plugin_insert_read (read_func_t *rf)
        int status;
        llentry_t *le;
 
+       cdtime_t now = cdtime ();
+       CDTIME_T_TO_TIMESPEC (now, &rf->rf_next_read);
+
        pthread_mutex_lock (&read_lock);
 
        if (read_list == NULL)
@@ -1544,13 +1547,25 @@ int plugin_dispatch_values (value_list_t *vl)
        if (vl->time == 0)
                vl->time = cdtime ();
 
-       if (vl->interval <= 0) {
+       if (vl->interval <= 0)
+       {
                plugin_ctx_t ctx = plugin_get_ctx ();
 
                if (ctx.interval != 0)
                        vl->interval = ctx.interval;
                else
-                       vl->interval = interval_g;
+               {
+                       char name[6 * DATA_MAX_NAME_LEN];
+                       FORMAT_VL (name, sizeof (name), vl);
+                       ERROR ("plugin_dispatch_values: Unable to determine "
+                                       "interval from context for "
+                                       "value list \"%s\". "
+                                       "This indicates a broken plugin. "
+                                       "Please report this problem to the "
+                                       "collectd mailing list or at "
+                                       "<http://collectd.org/bugs/>.", name);
+                       vl->interval = cf_get_default_interval ();
+               }
        }
 
        DEBUG ("plugin_dispatch_values: time = %.3f; interval = %.3f; "
@@ -1800,6 +1815,44 @@ void plugin_log (int level, const char *format, ...)
        }
 } /* void plugin_log */
 
+int parse_log_severity (const char *severity)
+{
+       int log_level = -1;
+
+       if ((0 == strcasecmp (severity, "emerg"))
+                       || (0 == strcasecmp (severity, "alert"))
+                       || (0 == strcasecmp (severity, "crit"))
+                       || (0 == strcasecmp (severity, "err")))
+               log_level = LOG_ERR;
+       else if (0 == strcasecmp (severity, "warning"))
+               log_level = LOG_WARNING;
+       else if (0 == strcasecmp (severity, "notice"))
+               log_level = LOG_NOTICE;
+       else if (0 == strcasecmp (severity, "info"))
+               log_level = LOG_INFO;
+#if COLLECT_DEBUG
+       else if (0 == strcasecmp (severity, "debug"))
+               log_level = LOG_DEBUG;
+#endif /* COLLECT_DEBUG */
+
+       return (log_level);
+} /* int parse_log_severity */
+
+int parse_notif_severity (const char *severity)
+{
+       int notif_severity = -1;
+
+       if (strcasecmp (severity, "FAILURE") == 0)
+               notif_severity = NOTIF_FAILURE;
+       else if (strcmp (severity, "OKAY") == 0)
+               notif_severity = NOTIF_OKAY;
+       else if ((strcmp (severity, "WARNING") == 0)
+                       || (strcmp (severity, "WARN") == 0))
+               notif_severity = NOTIF_WARNING;
+
+       return (notif_severity);
+} /* int parse_notif_severity */
+
 const data_set_t *plugin_get_ds (const char *name)
 {
        data_set_t *ds;
@@ -2062,25 +2115,11 @@ cdtime_t plugin_get_interval (void)
 {
        cdtime_t interval;
 
-       const char *interval_str;
-       double interval_dbl;
-
        interval = plugin_get_ctx().interval;
        if (interval > 0)
                return interval;
 
-       /* this should happen during initialization only */
-       interval_str = global_option_get ("Interval");
-       if (interval_str != NULL)
-       {
-               interval_dbl = atof (interval_str);
-               if (interval_dbl > 0.0)
-                       interval = DOUBLE_TO_CDTIME_T (interval_dbl);
-       }
-
-       if (interval > 0)
-               return interval;
-       return TIME_T_TO_CDTIME_T (10);
+       return cf_get_default_interval ();
 } /* cdtime_t plugin_get_interval */
 
 typedef struct {