X-Git-Url: https://git.octo.it/?p=collection4.git;a=blobdiff_plain;f=src%2Faction_show_graph.c;h=47d22c928c1e057b253f4f6d2a32db1a664736a2;hp=5304a2554d79dcd828bc578923da0dd320f0953b;hb=e3fb09073a64cc051c11c4a1bdcec493f937b764;hpb=6261a817494a678f8bc5dca6718c54c51e6421e0 diff --git a/src/action_show_graph.c b/src/action_show_graph.c index 5304a25..47d22c9 100644 --- a/src/action_show_graph.c +++ b/src/action_show_graph.c @@ -51,6 +51,7 @@ struct show_graph_data_s { graph_config_t *cfg; + const char *search_term; }; typedef struct show_graph_data_s show_graph_data_t; @@ -83,6 +84,32 @@ static int show_time_selector (__attribute__((unused)) void *user_data) /* {{{ * return (0); } /* }}} int show_time_selector */ +static int left_menu (void *user_data) /* {{{ */ +{ + show_graph_data_t *data = user_data; + + printf ("\n\n", + script_name ()); + + return (0); +} /* }}} int left_menu */ + static int show_instance_cb (graph_instance_t *inst, /* {{{ */ void *user_data) { @@ -90,6 +117,51 @@ static int show_instance_cb (graph_instance_t *inst, /* {{{ */ char descr[128]; char params[1024]; + if ((data->search_term != NULL) && (data->search_term[0] != 0)) + { + _Bool matches = 0; + char *term_lc = strtolower_copy (data->search_term); + + if (strncmp ("host:", term_lc, strlen ("host:")) == 0) + { + if (inst_matches_field (inst, GIF_HOST, term_lc + strlen ("host:"))) + matches = 1; + } + else if (strncmp ("plugin:", term_lc, strlen ("plugin:")) == 0) + { + if (inst_matches_field (inst, GIF_PLUGIN, term_lc + strlen ("plugin:"))) + matches = 1; + } + else if (strncmp ("plugin_instance:", term_lc, + strlen ("plugin_instance:")) == 0) + { + if (inst_matches_field (inst, GIF_PLUGIN_INSTANCE, + term_lc + strlen ("plugin_instance:"))) + matches = 1; + } + else if (strncmp ("type:", term_lc, strlen ("type:")) == 0) + { + if (inst_matches_field (inst, GIF_TYPE, term_lc + strlen ("type:"))) + matches = 1; + } + else if (strncmp ("type_instance:", term_lc, + strlen ("type_instance:")) == 0) + { + if (inst_matches_field (inst, GIF_TYPE_INSTANCE, + term_lc + strlen ("type_instance:"))) + matches = 1; + } + else if (inst_matches_string (data->cfg, inst, term_lc)) + { + matches = 1; + } + + free (term_lc); + + if (!matches) + return (0); + } /* if (data->search_term) */ + memset (descr, 0, sizeof (descr)); inst_describe (data->cfg, inst, descr, sizeof (descr)); html_escape_buffer (descr, sizeof (descr)); @@ -109,7 +181,16 @@ static int show_graph (void *user_data) /* {{{ */ { show_graph_data_t *data = user_data; - printf ("

Available instances

\n"); + if ((data->search_term == NULL) || (data->search_term[0] == 0)) + printf ("

All instances

\n"); + else + { + char *search_term_html = html_escape (data->search_term); + printf ("

Instances matching "%s"

\n", + search_term_html); + free (search_term_html); + } + printf ("\n"); @@ -130,12 +211,15 @@ int action_show_graph (void) /* {{{ */ if (pg_data.cfg == NULL) OUTPUT_ERROR ("gl_graph_get_selected () failed.\n"); + pg_data.search_term = param ("q"); + memset (tmp, 0, sizeof (tmp)); graph_get_title (pg_data.cfg, tmp, sizeof (tmp)); snprintf (title, sizeof (title), "Graph \"%s\"", tmp); title[sizeof (title) - 1] = 0; pg_callbacks.top_right = html_print_search_box; + pg_callbacks.middle_left = left_menu; pg_callbacks.middle_center = show_graph; pg_callbacks.middle_right = show_time_selector;