File: test.pl

package info (click to toggle)
mon-client 1.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 196 kB
  • ctags: 90
  • sloc: perl: 2,378; makefile: 2
file content (388 lines) | stat: -rwxr-xr-x 5,951 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
exit;
use Mon::Client;
use Data::Dumper;

print STDERR "new\n";
my $n = new Mon::Client (
    "host"      => "mon-bd2",
);

print STDERR "connect\n";
if (!defined $n->connect)
{
    die "could not connect\n";
}

print STDERR "list\n";
my %s = $n->list_opstatus;

print STDERR "dumper\n";
print Dumper (\%s), "\n";

$n->disconnect;

exit;


exit;
use Mon::Protocol;
use Data::Dumper;

$block= <<'EOF';
begin_block=UNKNOWN
begin=host1
var1=val1
var2=val2
end=host1
begin=host2
var1=people\0acannot\0ahandle\0aprofanity\0a\02\03\zz
var2=val2
var3=no\0this\0code\hasn't\0been\hacked
var4=this\0is\0just\0a\0test\0case\0so\don't\0get\0your\0panties\0into\0a\0knot
end=host2
end_block=UNKNOWN
EOF

my $p = new Mon::Protocol;
$p->parse_data ($block);

print Dumper ($p), "\n";

exit;
use Mon::Protocol;

my $p = new Mon::Protocol;

$p->add_to_section ("host1", {
    "var1"	=> "val1",
    "var2"	=> "val2",
});

$p->add_to_section ("host2", {
    "var1"	=> "val1\nyou\nhave\nbeen\nhacked\n",
    "var2"	=> "val2",
});

$a = $p->dump_data;

print "$a\n";
exit;

use Mon::Client;

my $c = new Mon::Client (
    host => "localhost",
);

die if (!defined $c);

$c->{"PROT"} = 9746;

$c->connect ("skip_protid" => 1);

if ($c->error ne "") {
    die "error: " . $c->error . "\n";
}

if ($c->connected)
{
	print "CONNECTED\n";
}
else
{
	print "NOT CONNECTED\n";
	print $c->error . "\n";
}

#my @s = $c->list_watch;

$c->disconnect;

exit;
use Mon::Client;

my $c = new Mon::Client (
    host => "localhost",
);

die if (!defined $c);

$c->connect;

if ($c->connected)
{
	print "CONNECTED\n";
}
else
{
	print "NOT CONNECTED\n";
	print $c->error . "\n";
}

my %op = $c->list_opstatus (["bd1", "ping"]);

foreach my $g (keys %op)
{
    foreach my $s (keys %{$op{$g}})
    {
	print "[$g] [$s]\n";
    	foreach my $v (keys %{$op{$g}->{$s}})
	{
	    print "     $v=[$op{$g}->{$s}->{$v}]\n";
	}
    }
}
$c->disconnect;

exit;
use Mon::Client;

my $c = new Mon::Client (
    host => "uplift",
);

die if (!defined $c);

if ($c->connected)
{
	print "CONNECTED\n";
}
else
{
	print "NOT CONNECTED\n";
}

if (!defined $c->connect)
{
    die "connect error: " . $c->error . "\n";
}

if ($c->connected)
{
	print "CONNECTED\n";
}
else
{
	print "NOT CONNECTED\n";
}

print $c->version, "\n";

my $v = $c->get ("router", "ping", "_timer");
if (!defined ($v))
{
    print STDERR "err getting\n";
}
else
{
    print "timer=$v\n";
}

my $v = $c->set ("router", "ping", "_fake_timer", "up it\n50");
if (!defined ($v))
{
    print STDERR "err setting\n";
}
else
{
    print "timer=$v\n";
}

my $v = $c->get ("router", "ping", "_fake_timer");
if (!defined ($v))
{
    print STDERR "err getting\n";
}
else
{
    print "timer=$v\n";
}


$c->disconnect;

exit;

my %op = $c->list_opstatus;

foreach my $g (keys %op)
{
    foreach my $s (keys %{$op{$g}})
    {
	print "[$g] [$s]\n";
    	foreach my $v (keys %{$op{$g}->{$s}})
	{
	    print "     $v=[$op{$g}->{$s}->{$v}]\n";
	}
    }
}

exit;


exit;
use Mon::Client;
use Data::Dumper;

my $n = new Mon::Client ( host => "localhost" );

die if (!defined $n);
$n->connect;

%a = $n->list_deps;

$n->disconnect;

print Dumper \%a, "\n";

exit;
use Mon::Client;
my $n = new Mon::Client ( host => "localhost" );
die if (!defined $n);
$n->connect;
@l = $n->list_alerthist;
$n->disconnect;

for my $line (sort {$a->{"time"} <=> $b->{"time"}} (@l)) {
    print "$line->{group} $line->{service} $line->{time}\n";
}

exit;
use Mon::Client;

$c = new Mon::Client (
    host => "localhost",
    port => 2583
);

die if (!defined $c);

$c->connect;

die "connect: " . $c->error . "\n" if ($c->error ne "");

%o = $c->list_opstatus;

die "list_opstatus: " . $c->error . "\n" if ($c->error ne "");

$c->quit;

foreach $g (keys %o) {
    foreach $s (keys %{$o{$g}}) {
    	foreach $v (keys %{$o{$g}->{$s}}) {
		print "[$g] [$s] [$v] = [$o{$g}->{$s}->{$v}]\n";
	}
    }
}

__END__
#
# $Id: test.pl,v 1.1.1.1 2004/06/18 14:25:16 trockij Exp $
#

use Mon::Client;

$a = new Mon::Client (
	host => "uplift",
);

if (!defined $a->connect) {
    die "could not connect: " . $a->error . "\n";
} else {
    print "connected\n";
}

if ((%o = $a->list_opstatus) == 0) {
    die "could not get optstatus: " . $a->error . "\n";
} else {
    print "got opstatus\n";
}

#$a->username ("mon");
#$a->password ("supermon");
#if (!defined ($a->login)) {
#    die "could not log in: " . $a->error . "\n";
#} else {
#    print "logged in\n";
#}

#if (!defined $a->stop) {
#    die "could not stop: " . $a->error . "\n";
#}

#if (!defined $a->start) {
#    die "could not start: " . $a->error . "\n";
#} else {
#    print "started scheduler\n";
#}

#if (!defined (%o = $a->list_failures)) {
#    die "could not get failures: " . $a->error . "\n";
#}

%d = $a->list_disabled();
if ($a->error) {
    die "could not get disabled: " . $a->error . "\n";
}

#if (!defined (@group = $a->list_group ("software"))) {
#    die "could not list group: " . $a->error . "\n";
#}


#if (!defined ($a->enable_host ("pgupta-dsl"))) {
#    die "could not enable host: " . $a->error . "\n";
#}

#if (!defined (($server, @pids) = $a->list_pids)) {
#    die "could not get failures: " . $a->error . "\n";
#}

if (!defined $a->disconnect) {
    die "could not disconnect: " . $a->error . "\n";
} else {
    print "disconnected\n";
}


&show_disabled;
&show_opstatus;

exit 0;




sub show_disabled {
    print "HOSTS\n";
    foreach $g (keys %{$d{hosts}}) {
	foreach $h (keys %{$d{hosts}{$g}}) {
	    print "group $g [$h]\n";
	}
    }

    print "SERVICES\n";
    foreach $g (keys %{$d{services}}) {
	foreach $s (keys %{$d{services}{$g}}) {
	    print "[$g] [$s]\n";
	}
    }

    print "WATCHES\n";
    foreach $g (keys %{$d{watches}}) {
	print "[$g]\n";
    }
}

sub show_opstatus {
    my ($g, $s, $k);

    print "OPSTATUS\n";
    foreach $g (keys %o) {
    	foreach $s (keys %{$o{$g}}) {
	    foreach $k (keys %{$o{$g}{$s}}) {
	    	print "[$g] [$s] [$k] [$o{$g}{$s}{$k}]\n";
	    }
	}
    }
}