summaryrefslogtreecommitdiff
path: root/xpp/utils/zaptel_hardware
blob: 26aa8390f39c4659c817a92bd5201933da276d8b (plain)
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
#! /usr/bin/perl -w
#
# Written by Oron Peled <oron@actcom.co.il>
# Copyright (C) 2007, Xorcom
# This program is free software; you can redistribute and/or
# modify it under the same terms as Perl itself.
#
# $Id:$
#
use strict;
BEGIN { my $dir = $0; $dir =~ s:/[^/]+$::; unshift(@INC, "$dir", "$dir/zconf"); }

use Zaptel;
use Zaptel::Span;
use Zaptel::Xpp;
use Zaptel::Xpp::Xbus;
use Zaptel::Hardware;

sub usage {
	die "Usage: $0\n";
}

@ARGV == 0 or usage;

my @hardware = Zaptel::Hardware->devices;
my @spans = Zaptel::spans;

sub show_xbus($) {
	my $xbus = shift or die;
	my @xpds = $xbus->xpds;
	my $connector = ($xbus->status eq 'CONNECTED') ? $xbus->connector : "MISSING";
	$connector = "(" . $connector . ")";
	printf "%-20s\n", $connector;
	foreach my $xpd (sort { $a->num <=> $b->num } @xpds) {
		my $reg = $xpd->zt_registration;
		my $span;
		my $spanstr;
		if($reg && @spans) {
			($span) = grep { $_->name eq $xpd->fqn } @spans;
			$spanstr = ($span) ? ("Span " . $span->num) : "";
		} else {
			$spanstr = "Unregistered";
		}
		my $master = '';
		$master = "XPP-SYNC" if $xpd->is_sync_master;
		$master .= " ZAPTEL-SYNC" if defined($span) && $span->is_zaptel_sync_master;
		printf "\t%-10s: %-8s %s %s\n", $xpd->fqn, $xpd->type, $spanstr, $master;
	}
}

my %seen;
my $format = "%-20s\t%4s:%4s %-12s ";

foreach my $dev (@hardware) {
	my $xbus = $dev->xbus;
	my $driver = $dev->driver || "";
	$driver = "[$driver]";
	printf $format, $dev->hardware_name, $dev->vendor, $dev->product, $driver;
	if(!$xbus) {
		printf "\n";
		next;
	}
	$seen{$xbus->name} = 1;
	show_xbus($xbus);
}

my $notified_lost = 0;
foreach my $xbus (Zaptel::Xpp::xbuses('SORT_CONNECTOR')) {
	if(!$seen{$xbus->name}) {
		print "----------- XPP Spans with disconnected hardware -----------\n"
			unless $notified_lost++;
		printf $format, $xbus->name, '', '', "NO HARDWARE";
		show_xbus($xbus);
	}
}


__END__

=head1 NAME

zaptel_hardware - Shows Zaptel hardware devices.

=head1 SYNOPSIS

zaptel_hardware

=head1 DESCRIPTION

Show all zaptel hardware devices, both used and unused.