How can I send data to Magma server without installing the client?

Discussion forum for the Monitor And Graphing Management Archive plugins for LabTech.
Post Reply
User avatar
Cubert
Posts: 2430
Joined: Tue Dec 29, 2015 7:57 pm
8
Contact:

How can I send data to Magma server without installing the client?

Post by Cubert »

How can I send data to Magma without installing the client?

If you cannot install any "foreign" tools on your system, then sending data to Magma may be a challenge. But if you have access to either Perl, BASH or telnet on the system then it is possible.

Perl version:

Code: Select all

#!/usr/bin/perl
#
sub sendToMagma {
	use IO::Socket;
	my($server,$port,$msg) = @_ ;
	my $response;
	my $sock = new IO::Socket::INET (
			PeerAddr => $server,
			PeerPort => $port,
			Proto => 'tcp',
		);
	die "Could not create socket: $!\n" unless $sock;
	print $sock $msg;
	shutdown($sock, 1);
	while ($response=<$sock>)
	{
		print "$response";
	}
	close($sock);
}

$host = $ARGV[0];
if ($#ARGV != 2) {
  $port = 1984;
  $msg = $ARGV[1];
}
else {
  $port = $ARGV[1];
  $msg = $ARGV[2];
}

sendToMagma($host, $port, $msg);
BASH version:

Code: Select all

#!/bin/bash
#
HOST="$1" ; shift
if test $# -gt 1; then
  PORT="$1"
  shift
else
  PORT="1984"
fi
MSG="$1"

exec 3<>/dev/tcp/$HOST/$PORT || exit 1
echo "$MSG" >&3

exit 0
NOTE: The BASH support for using TCP sockets may be disabled at compile-time - some believe it is a security risk to have such an easy way of doing network I/O without requiring any special tools.



Bourne / Korn shell (requires telnet):

Code: Select all

#!/bin/sh
#
HOST="$1" ; shift
if test $# -gt 1; then
  PORT="$1"
  shift
else
  PORT="1984"
fi
MSG="$1"

( echo "$MSG"; sleep 1 ) | telnet $HOST $PORT 2>&1 >/dev/null | grep -v "closed by foreign host"
Both of these take 2 or 3 parameters: The Magma server host (hostname or IP-address), optionally the portnumber (1984 by default if not specified), and the message that will be sent. The Perl version will both send data to Magma and print out any response that is sent back - the shell-versions can only be used to send data.

User avatar
Cubert
Posts: 2430
Joined: Tue Dec 29, 2015 7:57 pm
8
Contact:

Re: How can I send data to Magma server without installing the client?

Post by Cubert »

You can also send data using another client as a proxy. Both BBWin and Powershell agents provide this feature.

Have a script create a text file in one of the following directories without a file extension.

In BBWin : C:\Program Files (x86)\BBWin\tmp\

In PoSh : C:\Windows\LTSvc\Magma\tmp\

the name of the file will be the column name you will see and the format of the file is as follows

Code: Select all

STATUS MYHOSTNAME.test COLOR DATE  NewLine NewLine Any Data you want to add to display
A live example for BBWin appears the first line needs to be:

Filename would be "mytest" without a .txt on the end of file name, we would place file in C:\Program Files (x86)\BBWin\tmp\
with the following info (colour date time [hostname])

Code: Select all

red 20/11/2014 12:53:00 xyz.pqd.com
 
Some data that is relevant to monitor...
 
 
The rest of the file can be pretty much anything

Post Reply

Return to “Magma For LabTech”