[hobbit] bb cmd protocol? (was [hobbit] Windows version of a fully functional bb command)

Ralph Mitchell ralphmitchell at gmail.com
Fri Mar 21 02:22:18 CET 2008


On Thu, Mar 20, 2008 at 5:43 PM, Charles Jones <jonescr at cisco.com> wrote:

>  Henrik,
>
> I'm talking about the connection protocol, not the message protocol. So
> that I can write code that can connect to a BBDISPLAY and send/receive data,
> without shelling out and using a bb binary.  I've tried telnetting to port
> 1984 and typing various commands, and also using netcat, none of which seem
> to work, so I suspect that hobbitd is expecting to see some certain
> characters before it will accept a command.
>
> -Charles
>


Would bb.pl be of any use to you??  As found on deadcat.net:

#!/usr/bin/perl -w

# bb.pl
#
# BIG BROTHER CLIENT PROGRAM
# Nicolas Chuche <chuche at teaser.fr>
# Version 1
# Jul 15, 2000

# This program is a remake of bb.c in perl.
# I've do that to :
# 1. have a real client for my NT servers
# 2. see what it done in perl

# I've tried to have full compatibility so i've keep all the error
# messages.

# If you want to use it, just replace the original bb by this file in
# BBHOME/bin

# The header of bb.c :

# SENDS THE INPUT LINE TO THE DAEMON ON THE BIG BROTHER PORT
# Format: bb IP-ADDR [<LINE>|-]
#
#    IP-ADDR:    IP-ADDR OF THE SERVER
#    LINE:        <page|status|summary> <DATA>
#        DATA:    for page:    <NUMERIC MESSAGE><status-msg>
#            for status:    <machine><color-code><status-msg>
#            fro summary:    <summary name><color-code><http link>
#
#    -        Will read from standard input a one line status
#                message.
#

use strict;
use Socket;

my $PORT              = 1984;                    # The bbd port
my $PAGELEVELSDEFAULT = "red purple";            # the default page level
my $MAXBBLINE         = 256;                     # the max input line length

# sub debug { print STDERR shift;};              # debug message : uncomment
this line
sub debug {};                                    # and comment this one

@ARGV == 2                  or &Usage;
my ($server, $line) = @ARGV or &Usage;

# take the standart input if second arg is "-"
if ($line eq '-') {
  debug("bb gets its input from stdin\n");
  while (<STDIN>) {
    chomp;
    $_ = substr($_, 0, $MAXBBLINE - 1);
    debug("data came in [$_]\n");
    bb_notify($server, $_);
  }
  debug("Done\n");
} else {
  bb_notify($server, $line);
}

exit(0);

sub bb_notify {
  my ($machine, $data) = @_;
  my (@bbdisplays, @bbpagers, $bbpage, $pagelevels) = ();

  @bbdisplays = split /\s+/, $ENV{BBDISPLAYS} if defined $ENV{BBDISPLAYS};
  debug("Sending: ** $data ** to $machine - @bbdisplays\n");
  bb_send($machine, \@bbdisplays, $data);

  $bbpage     = $ENV{BBPAGE};# if defined $ENV{BBPAGE};
  $pagelevels = ((defined $ENV{PAGELEVELS}) && $ENV{PAGELEVELS}) ?
$ENV{PAGELEVELS} : $PAGELEVELSDEFAULT;

  # paging or not paging ?
  if( $bbpage && $pagelevels ) {
    my ($type, $machine, $color, $message) = $data =~
/^(\S+)\s+(\S+)\s+(\S+)\s+(.*)$/;

    debug("v1:[$type] v2:[$machine] v3:[$color] v4:[$message]\n");

    if ($type =~ /status/ && $pagelevels =~ /$color/) {
      $data =~ s/^(\s*status\S*\s+)/page /;                # Change msg type
      @bbpagers   = split /\s+/, $ENV{BBPAGERS} if defined $ENV{BBPAGERS};
      debug("Sending: ** $data ** to $bbpage - @bbpagers\n");
      bb_send($bbpage,\@bbpagers,$data);    # SEND IT ACROSS TO BBPAGER
    }
  }
}

# ##############
# Send a message

sub bb_send {
  my ($bbdisp, $machinelist, $message) = @_;
  my (%machine, @machinelist) = ();

  @machinelist = ($bbdisp ne "0.0.0.0") ? ($bbdisp) : @$machinelist;

  debug("BOX: $bbdisp\nBOXES: @machinelist\n");

  for my $server (@machinelist) {
    my ($port, $iaddr, $paddr, $proto);    # Variable réseau

    # don't send the message twice to the same machine
    next if $machine{$server};
    $machine{$server} = 1;

    debug("Host: $server\n");

    $iaddr   = inet_aton($server)              || warn "bb: Unknown host:
$server\n", next;
    $paddr   = sockaddr_in($PORT, $iaddr);
    $proto   = getprotobyname('tcp');

    socket(SOCK, PF_INET, SOCK_STREAM, $proto) || warn "bb: Can't open
stream socket\n", next;
    connect(SOCK, $paddr)                      || warn "bb: CAN'T CONNECT TO
bbd SERVER @ $server", next;
    # select((select(SOCK), $| = 1)[0]);         # unbuffer the socket
    print SOCK $message;
    close (SOCK);
  }
  debug("Host list done\n");
}

# ###########
# Print usage

sub Usage {
  print STDERR <<EOF;
bb: incorrect number of arguments
Format: <IP-ADDR> <DATA>
EOF
  exit(1);
}


Ralph Mitchell
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xymon.com/pipermail/xymon/attachments/20080320/3e736f48/attachment.html>


More information about the Xymon mailing list