src/graph_instance.[ch]: Implement "inst_data_to_json".
[collection4.git] / src / action_list_graphs.c
1 /**
2  * collection4 - action_list_graphs.c
3  * Copyright (C) 2010  Florian octo Forster
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  * 
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA  02110-1301  USA
19  *
20  * Authors:
21  *   Florian octo Forster <ff at octo.it>
22  **/
23
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <errno.h>
28
29 #include "action_list_graphs.h"
30 #include "common.h"
31 #include "graph.h"
32 #include "graph_list.h"
33 #include "utils_cgi.h"
34
35 #include <fcgiapp.h>
36 #include <fcgi_stdio.h>
37
38 static int left_menu (__attribute__((unused)) void *user_data) /* {{{ */
39 {
40   printf ("\n<ul class=\"menu left\">\n"
41       "  <li><a href=\"%s?action=search\">Search</a></li>\n"
42       "  <li><a href=\"%s?action=list_hosts\">All hosts</a></li>\n"
43       "</ul>\n",
44       script_name (), script_name ());
45
46   return (0);
47 } /* }}} int left_menu */
48
49 static int print_one_graph (graph_config_t *cfg, /* {{{ */
50     __attribute__((unused)) void *user_data)
51 {
52   char params[1024];
53   char title[1024];
54   size_t num_instances;
55
56   num_instances = graph_num_instances (cfg);
57   if (num_instances < 1)
58     return (0);
59
60   memset (title, 0, sizeof (title));
61   graph_get_title (cfg, title, sizeof (title));
62   html_escape_buffer (title, sizeof (title));
63
64   memset (params, 0, sizeof (params));
65   graph_get_params (cfg, params, sizeof (params));
66   html_escape_buffer (params, sizeof (params));
67
68   printf ("      <li class=\"graph\"><a href=\"%s?action=show_graph;%s\">"
69       "%s</a> <span class=\"num_instances\">(%lu %s)</span></li>\n",
70       script_name (), params, title,
71       (unsigned long) num_instances,
72       (num_instances == 1) ? "instance" : "instances");
73
74   return (0);
75 } /* }}} int print_one_graph */
76
77 static int print_all_graphs (__attribute__((unused)) void *user_data) /* {{{ */
78 {
79   const char *dynamic;
80   _Bool include_dynamic = 0;
81
82   dynamic = param ("dynamic");
83   if ((dynamic != NULL)
84       && (strcmp ("true", dynamic) == 0))
85     include_dynamic = 1;
86
87   printf ("    <ul class=\"graph_list\">\n");
88   gl_graph_get_all (include_dynamic, print_one_graph, /* user_data = */ NULL);
89   printf ("    </ul>\n");
90
91   if (!include_dynamic)
92   {
93     printf ("    <div><a href=\"%s?action=list_graphs;dynamic=true\">"
94         "List dynamic graphs, too."
95         "</a></div>\n", script_name ());
96   }
97
98   return (0);
99 } /* }}} int print_all_graphs */
100
101 int action_list_graphs (void) /* {{{ */
102 {
103   page_callbacks_t pg_callbacks = PAGE_CALLBACKS_INIT;
104   char title[512];
105
106   strncpy (title, "List of all graphs", sizeof (title));
107   title[sizeof (title) - 1] = 0;
108
109   pg_callbacks.top_right = html_print_search_box;
110   pg_callbacks.middle_left = left_menu;
111   pg_callbacks.middle_center = print_all_graphs;
112
113   html_print_page (title, &pg_callbacks, /* user data = */ NULL);
114
115   return (0);
116 } /* }}} int action_list_graphs */
117
118 /* vim: set sw=2 sts=2 et fdm=marker : */