Documentation ¶
Overview ¶
Package nscatools is a flexible library that allows you to easily create a custom NSCA (Nagios Service Check Acceptor) client and server in pure Go. Note: the package requires libmcrypt to work for now (under Debian-based systems, the packages are named libmcrypt4 and libmcrypt-dev)
Index ¶
- Constants
- func HandleClient(conf *Config, conn net.Conn, logErr *log.Logger) error
- func MCrypt(algo string, blocks, key, iv []byte, decrypt bool) error
- func SendStatus(conf *Config, clientHost string, service string, status int16, message string) error
- func StartServer(conf *Config, debug bool)
- type Config
- type DataPacket
- type InitPacket
Constants ¶
const ( EncryptNone = iota // no encryption EncryptXOR // Simple XOR (No security, just obfuscation, but very fast) EncryptDES // DES Encrypt3DES // 3DES or Triple DES EncryptCAST128 // CAST-128 EncryptCAST256 // CAST-256 EncryptXTEA // xTEA Encrypt3WAY // 3-WAY EncryptBLOWFISH // SKIPJACK EncryptTWOFISH // TWOFISH EncryptLOKI97 // LOKI97 EncryptRC2 // RC2 EncryptARCFOUR // RC4 EncryptRC6 // RC6 - Unsupported in standard NSCA EncryptRIJNDAEL128 // AES-128 EncryptRIJNDAEL192 // AES-192 EncryptRIJNDAEL256 // AES-256 EncryptMARS // MARS - Unsupported in standard NSCA EncryptPANAMA // PANAMA - Unsupported in standard NSCA EncryptWAKE // WAKE EncryptSERPENT // SERPENT EncryptIDEA // IDEA - Unsupported in standard NSCA EncryptENIGMA // ENIGMA (Unix crypt) EncryptGOST // GOST EncryptSAFER64 // SAFER-sk64 EncryptSAFER128 // SAFER-sk128 EncryptSAFERPLUS // SAFER+ )
Encrypt* are the encryptions supported by the standard NSCA configuration
const ( StateOK = iota StateWarning StateCritical StateUnknown )
State* are the states understood by NSCA
const LongPacketLength = 4304
LongPacketLength - long one:
const MaxPacketAge = 30
MaxPacketAge is the number of seconds difference allowed between the initialization packet epoch and the epoch of the data packet received
const ShortPacketLength = 720
ShortPacketLength - short one:
Variables ¶
This section is empty.
Functions ¶
func HandleClient ¶
HandleClient takes care of a client connection. Use the PacketHandler parameter to define what you want to do with the DataPacket once it is decrypted and trasformed to a DataPacket struct. Only the errors will be logged via the logger parameter
func MCrypt ¶
MCrypt uses libmcrypt to decrypt/encrypt the data received from the send_nsca client. When I have some more time I'll dig to find out why I'm not able to decrypt directly using the NewCFBDecrypter To decrypt, set the decrypt parameter to true, else it will encrypt.
func SendStatus ¶
func SendStatus(conf *Config, clientHost string, service string, status int16, message string) error
SendStatus connects to the nsca server and sends the provided data in the right format. If you want to send a host status (as opposed to a service status), just let the "service" parameter empty
Types ¶
type Config ¶
type Config struct { // When initiating a server, Host is the IP to listen on // When initiating a client, Host is the target nsca host Host string // When initializing a server, Port is the port to listen on // When initializing a client, Port is the port of the target nsca server Port uint16 // Encryption methid to use based on the standard NSCA encryptions list EncryptionMethod int // Password is used to encypt and decrypt the messages if EncryptionMethod is // not set to 0. Password string // Max size of each fields MaxHostnameSize uint16 MaxDescriptionSize uint16 MaxPluginOutputSize uint16 // PacketHandler is the function that will handle the DataPacket in the // HandleClient function. You define waht you want to do with the DataPacket // once decrypted and transformed to a DataPacket struct. // This function should follow this: func(*dataPacket) error PacketHandler dataHandler }
Config manages the configuration of the client and server objects
type DataPacket ¶
type DataPacket struct { Version int16 Crc uint32 Timestamp uint32 State int16 HostName string Service string PluginOutput string Ipkt *InitPacket Password []byte Encryption int }
DataPacket stores the data received for the client-server communication
func NewDataPacket ¶
func NewDataPacket(encryption int, password []byte, ipkt *InitPacket) *DataPacket
NewDataPacket initializes a new blank data packet
func (*DataPacket) CalculateCrc ¶
func (p *DataPacket) CalculateCrc(buffer []byte) uint32
CalculateCrc returns the Crc of a packet ready to be sent over the network, ignoring the Crc data part of it as it's done in the original nsca code
func (*DataPacket) Decrypt ¶
func (p *DataPacket) Decrypt(buffer []byte) error
Decrypt decrypts a buffer
func (*DataPacket) Encrypt ¶
func (p *DataPacket) Encrypt(buffer []byte) error
Encrypt encrypts a buffer
func (*DataPacket) Read ¶
func (p *DataPacket) Read(conn io.Reader) error
Read gets the data packet and populates the attributes of the DataPacket according. When encountering an error, it returns the error and don't process further.
func (*DataPacket) Write ¶
func (p *DataPacket) Write(w io.Writer) error
Write generates the buffer to write to the writer based on the populated fields of the DataPacket instance encrypts it if needed and send it to the writer. When encountering an error, it returns the error and don't process further.
type InitPacket ¶
InitPacket is used during the handshake with the client
func NewInitPacket ¶
func NewInitPacket() (*InitPacket, error)
NewInitPacket initialize an InitPacket by creating a random initialization vector and filling the timestamp attribute with the current epoch time