use utf8;
use warnings; no warnings "redefine";
use strict;
use Dbase::Globals qw(ipinfo);
use Dbase::Help qw(DoFn DoSelect isotime);
use Fehler qw(problem);
use Loader qw(line_printer);

sub list_messstelle($) {
    my ( $idi ) = @_;
    line_printer;

    my ( $timestamp, $name, $ipk, $typid, $typname, $oid, $beginn, $ende, $info )
      = DoFn <<_
SELECT mess_stelle.timestamp,
       mess_stelle.name,
       ipkunde.id,
       mess_stelle.typ,
       mess_typ.name,
       CONCAT( mess_typ.oid_praefix, mess_stelle.oid_suffix ) AS oid,
       mess_stelle.beginn,
       mess_stelle.ende,
       mess_stelle.info
  FROM mess_stelle JOIN ipkunde ON mess_stelle.snmp_host = ipkunde.id
    JOIN mess_typ ON mess_stelle.typ = mess_typ.id
 WHERE mess_stelle.id = $idi
_
      or return problem "MessTyp #$idi nicht gefunden.";

    print $Db::pr_fh "ID          : $idi\n";
    print $Db::pr_fh 'Timestamp   : ' . isotime($timestamp) . "\n";
    print $Db::pr_fh 'FQDN        : ' . ipinfo($ipk) . "\n";
    print $Db::pr_fh "Name        : $name\n";
    print $Db::pr_fh "Typ         : #$typid:$typname\n";
    print $Db::pr_fh "OID-Ast     : $oid\n" if $oid;

    my @hwv;
    DoSelect {
        my ( $hid, $hname ) = @_;
        push @hwv, "#$hid" . ( defined $hname ? ":$hname" : '' );
    } <<_;
SELECT hardware.id, hardware.name
  FROM hardware JOIN mess_verbraucher ON hardware.id = mess_verbraucher.hardware
 WHERE mess_verbraucher.mess_stelle = $idi
_

    if (@hwv) {
        print $Db::pr_fh "Verbraucher : " . join("\n            : ", @hwv ) . "\n";
    }
    print $Db::pr_fh 'Beginn      : ' . isotime($beginn) . "\n" if $beginn;
    print $Db::pr_fh 'Ende        : ' . isotime($ende) . "\n" if $ende;
    print $Db::pr_fh 'Info        : ' . ( defined $info ? $info : '' ) . "\n" if $info;

}

1;
