Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2990 from furiel/generate-config-graph
visualize config graph
- Loading branch information
Showing
13 changed files
with
365 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env python | ||
import json, sys | ||
|
||
j = None | ||
|
||
if len(sys.argv) == 1: | ||
j = json.loads(sys.stdin.read()) | ||
else: | ||
file_name = sys.argv[1] | ||
with open(file_name) as f: | ||
j = json.loads(f.read()) | ||
|
||
nodes = j["nodes"] | ||
arcs = j["arcs"] | ||
|
||
print("digraph D {") | ||
for node in nodes: | ||
print(" Node{} [label=\"{} {}\"]".format(node["node"], node["node"], ", ".join(node["info"]))) | ||
for arc in arcs: | ||
print(" Node{} -> Node{} [label=\"{}\"]".format(arc["from"], arc["to"], arc["type"])) | ||
print("}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright (c) 2019 Balabit | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* As an additional exemption you are allowed to compile & link against the | ||
* OpenSSL libraries as published by the OpenSSL project. See the file | ||
* COPYING for details. | ||
* | ||
*/ | ||
|
||
#include "cfg-walker.h" | ||
#include "logpipe.h" | ||
|
||
Arc * | ||
arc_new(LogPipe *from, LogPipe *to, ArcType arc_type) | ||
{ | ||
Arc *self = g_new0(Arc, 1); | ||
self->from = from; | ||
self->to = to; | ||
self->arc_type = arc_type; | ||
|
||
return self; | ||
}; | ||
|
||
void | ||
arc_free(Arc *self) | ||
{ | ||
g_free(self); | ||
} | ||
|
||
static guint | ||
arc_hash(Arc *arc) | ||
{ | ||
return g_direct_hash(arc->from); | ||
} | ||
|
||
static gboolean | ||
arc_equal(Arc *arc1, Arc *arc2) | ||
{ | ||
return arc1->to == arc2->to; | ||
} | ||
|
||
static void walk_pipe(LogPipe *self, gpointer *user_data); | ||
|
||
static void | ||
_add_arc_and_walk(Arc *arc, gpointer *user_data) | ||
{ | ||
GHashTable **arcs = user_data[1]; | ||
g_hash_table_insert(*arcs, arc, NULL); | ||
walk_pipe(arc->to, user_data); | ||
} | ||
|
||
static void | ||
walk_pipe(LogPipe *self, gpointer *user_data) | ||
{ | ||
|
||
GHashTable **nodes = user_data[0]; | ||
|
||
if (g_hash_table_contains(*nodes, self)) | ||
return; | ||
|
||
g_hash_table_insert(*nodes, self, NULL); | ||
|
||
GList *new_arcs = log_pipe_get_arcs(self); | ||
g_list_foreach(new_arcs, (GFunc)_add_arc_and_walk, user_data); | ||
g_list_free(new_arcs); | ||
} | ||
|
||
void | ||
cfg_walker_get_graph(GPtrArray *start_nodes, GHashTable **nodes, GHashTable **arcs) | ||
{ | ||
*nodes = g_hash_table_new(g_direct_hash, g_direct_equal); | ||
*arcs = g_hash_table_new_full((GHashFunc)arc_hash, (GEqualFunc)arc_equal, (GDestroyNotify)arc_free, NULL); | ||
|
||
g_ptr_array_foreach(start_nodes, (GFunc)walk_pipe, (gpointer []) | ||
{ | ||
nodes, arcs | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2019 Balabit | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
* | ||
* As an additional exemption you are allowed to compile & link against the | ||
* OpenSSL libraries as published by the OpenSSL project. See the file | ||
* COPYING for details. | ||
* | ||
*/ | ||
|
||
#ifndef CFG_WALKER_H_INCLUDED | ||
#define CFG_WALKER_H_INCLUDED | ||
|
||
#include "syslog-ng.h" | ||
|
||
typedef enum | ||
{ | ||
ARC_TYPE_PIPE_NEXT, | ||
ARC_TYPE_NEXT_HOP | ||
} ArcType; | ||
|
||
typedef struct | ||
{ | ||
LogPipe *from; | ||
LogPipe *to; | ||
ArcType arc_type; | ||
} Arc; | ||
|
||
void cfg_walker_get_graph(GPtrArray *start_nodes, GHashTable **nodes, GHashTable **arcs); | ||
Arc *arc_new(LogPipe *from, LogPipe *to, ArcType arc_type); | ||
void arc_free(Arc *self); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.