1exit;
2use Mon::Protocol;
3use Data::Dumper;
4
5$block= <<'EOF';
6begin_block=UNKNOWN
7begin=host1
8var1=val1
9var2=val2
10end=host1
11begin=host2
12var1=fuck\0ayou\0avery\0amuch\0a\02\03\zz
13var2=val2
14end=host2
15end_block=UNKNOWN
16EOF
17
18my $p = new Mon::Protocol;
19$p->parse_data ($block);
20
21print Dumper ($p), "\n";
22
23exit;
24use Mon::Protocol;
25
26my $p = new Mon::Protocol;
27
28$p->add_to_section ("host1", {
29    "var1"	=> "val1",
30    "var2"	=> "val2",
31});
32
33$p->add_to_section ("host2", {
34    "var1"	=> "val1\nfuck\nyou\n",
35    "var2"	=> "val2",
36});
37
38$a = $p->dump_data;
39
40print "$a\n";
41exit;
42
43use Mon::Client;
44
45my $c = new Mon::Client (
46    host => "localhost",
47);
48
49die if (!defined $c);
50
51$c->{"PROT"} = 9746;
52
53$c->connect ("skip_protid" => 1);
54
55if ($c->error ne "") {
56    die "error: " . $c->error . "\n";
57}
58
59if ($c->connected)
60{
61	print "CONNECTED\n";
62}
63else
64{
65	print "NOT CONNECTED\n";
66	print $c->error . "\n";
67}
68
69#my @s = $c->list_watch;
70
71$c->disconnect;
72
73exit;
74use Mon::Client;
75
76my $c = new Mon::Client (
77    host => "localhost",
78);
79
80die if (!defined $c);
81
82$c->connect;
83
84if ($c->connected)
85{
86	print "CONNECTED\n";
87}
88else
89{
90	print "NOT CONNECTED\n";
91	print $c->error . "\n";
92}
93
94my %op = $c->list_opstatus (["bd1", "ping"]);
95
96foreach my $g (keys %op)
97{
98    foreach my $s (keys %{$op{$g}})
99    {
100	print "[$g] [$s]\n";
101    	foreach my $v (keys %{$op{$g}->{$s}})
102	{
103	    print "     $v=[$op{$g}->{$s}->{$v}]\n";
104	}
105    }
106}
107$c->disconnect;
108
109exit;
110use Mon::Client;
111
112my $c = new Mon::Client (
113    host => "uplift",
114);
115
116die if (!defined $c);
117
118if ($c->connected)
119{
120	print "CONNECTED\n";
121}
122else
123{
124	print "NOT CONNECTED\n";
125}
126
127if (!defined $c->connect)
128{
129    die "connect error: " . $c->error . "\n";
130}
131
132if ($c->connected)
133{
134	print "CONNECTED\n";
135}
136else
137{
138	print "NOT CONNECTED\n";
139}
140
141print $c->version, "\n";
142
143my $v = $c->get ("router", "ping", "_timer");
144if (!defined ($v))
145{
146    print STDERR "err getting\n";
147}
148else
149{
150    print "timer=$v\n";
151}
152
153my $v = $c->set ("router", "ping", "_fake_timer", "up it\n50");
154if (!defined ($v))
155{
156    print STDERR "err setting\n";
157}
158else
159{
160    print "timer=$v\n";
161}
162
163my $v = $c->get ("router", "ping", "_fake_timer");
164if (!defined ($v))
165{
166    print STDERR "err getting\n";
167}
168else
169{
170    print "timer=$v\n";
171}
172
173
174$c->disconnect;
175
176exit;
177
178my %op = $c->list_opstatus;
179
180foreach my $g (keys %op)
181{
182    foreach my $s (keys %{$op{$g}})
183    {
184	print "[$g] [$s]\n";
185    	foreach my $v (keys %{$op{$g}->{$s}})
186	{
187	    print "     $v=[$op{$g}->{$s}->{$v}]\n";
188	}
189    }
190}
191
192exit;
193
194
195exit;
196use Mon::Client;
197use Data::Dumper;
198
199my $n = new Mon::Client ( host => "localhost" );
200
201die if (!defined $n);
202$n->connect;
203
204%a = $n->list_deps;
205
206$n->disconnect;
207
208print Dumper \%a, "\n";
209
210exit;
211use Mon::Client;
212my $n = new Mon::Client ( host => "localhost" );
213die if (!defined $n);
214$n->connect;
215@l = $n->list_alerthist;
216$n->disconnect;
217
218for my $line (sort {$a->{"time"} <=> $b->{"time"}} (@l)) {
219    print "$line->{group} $line->{service} $line->{time}\n";
220}
221
222exit;
223use Mon::Client;
224
225$c = new Mon::Client (
226    host => "localhost",
227    port => 2583
228);
229
230die if (!defined $c);
231
232$c->connect;
233
234die "connect: " . $c->error . "\n" if ($c->error ne "");
235
236%o = $c->list_opstatus;
237
238die "list_opstatus: " . $c->error . "\n" if ($c->error ne "");
239
240$c->quit;
241
242foreach $g (keys %o) {
243    foreach $s (keys %{$o{$g}}) {
244    	foreach $v (keys %{$o{$g}->{$s}}) {
245		print "[$g] [$s] [$v] = [$o{$g}->{$s}->{$v}]\n";
246	}
247    }
248}
249
250__END__
251#
252# $Id: test.pl 1.1 Mon, 21 Aug 2000 08:30:45 -0700 trockij $
253#
254
255use Mon::Client;
256
257$a = new Mon::Client (
258	host => "uplift",
259);
260
261if (!defined $a->connect) {
262    die "could not connect: " . $a->error . "\n";
263} else {
264    print "connected\n";
265}
266
267if ((%o = $a->list_opstatus) == 0) {
268    die "could not get optstatus: " . $a->error . "\n";
269} else {
270    print "got opstatus\n";
271}
272
273#$a->username ("mon");
274#$a->password ("supermon");
275#if (!defined ($a->login)) {
276#    die "could not log in: " . $a->error . "\n";
277#} else {
278#    print "logged in\n";
279#}
280
281#if (!defined $a->stop) {
282#    die "could not stop: " . $a->error . "\n";
283#}
284
285#if (!defined $a->start) {
286#    die "could not start: " . $a->error . "\n";
287#} else {
288#    print "started scheduler\n";
289#}
290
291#if (!defined (%o = $a->list_failures)) {
292#    die "could not get failures: " . $a->error . "\n";
293#}
294
295%d = $a->list_disabled();
296if ($a->error) {
297    die "could not get disabled: " . $a->error . "\n";
298}
299
300#if (!defined (@group = $a->list_group ("software"))) {
301#    die "could not list group: " . $a->error . "\n";
302#}
303
304
305#if (!defined ($a->enable_host ("pgupta-dsl"))) {
306#    die "could not enable host: " . $a->error . "\n";
307#}
308
309#if (!defined (($server, @pids) = $a->list_pids)) {
310#    die "could not get failures: " . $a->error . "\n";
311#}
312
313if (!defined $a->disconnect) {
314    die "could not disconnect: " . $a->error . "\n";
315} else {
316    print "disconnected\n";
317}
318
319
320&show_disabled;
321&show_opstatus;
322
323exit 0;
324
325
326
327
328sub show_disabled {
329    print "HOSTS\n";
330    foreach $g (keys %{$d{hosts}}) {
331	foreach $h (keys %{$d{hosts}{$g}}) {
332	    print "group $g [$h]\n";
333	}
334    }
335
336    print "SERVICES\n";
337    foreach $g (keys %{$d{services}}) {
338	foreach $s (keys %{$d{services}{$g}}) {
339	    print "[$g] [$s]\n";
340	}
341    }
342
343    print "WATCHES\n";
344    foreach $g (keys %{$d{watches}}) {
345	print "[$g]\n";
346    }
347}
348
349sub show_opstatus {
350    my ($g, $s, $k);
351
352    print "OPSTATUS\n";
353    foreach $g (keys %o) {
354    	foreach $s (keys %{$o{$g}}) {
355	    foreach $k (keys %{$o{$g}{$s}}) {
356	    	print "[$g] [$s] [$k] [$o{$g}{$s}{$k}]\n";
357	    }
358	}
359    }
360}
361