send_nsca

send_nsca.py: A replacement for the C-based send_nsca, able to be run in pure-python. Depends on PyCrypto and Python >= 2.6.

Heavily inspired by (and protocol-compatible with) the original send_nsca, written by Ethan Galstad <nagios@nagios.org>, which was available under the terms of the GNU General Public License v2.

Not quite feature-complete. The simpler encryption algorithms (null, XOR, DES, 3DES, Blowfish, ARC2, and CAST) work, but AES doesn’t work (the AES that nsca uses isn’t compatible with PyCrypto’s for reasons that I haven’t yet determined). Also, ARC4 is broken upstream, and I didn’t fix it.

Copyright (C) 2012 Yelp, Inc. Written by James Brown <jbrown@yelp.com>

This software is available under the terms of the Lesser GNU Public License, Version 2.1

Forked from this repository at Github

Changes on this fork:

  • All code in one file.

  • PEP 8

  • Python 3 only

  • Add arguments: password and encryption_method. No need for a configuration file anymore.

  • Works without pycrypto (only encryption_method 1 works)

Another interesting Python package that sends NSCA messages is pynsca.

Usage

The convenience function:

from send_nsca import send_nsca, STATE_OK
send_nsca.send_nsca(
    status=STATE_OK,
    host_name='host',
    service_name='service',
    text_output='output',
    remote_host='1.2.3.4',
    password='1234'
    encryption_method=1
)

The class:

from send_nsca import NscaSender, STATE_OK
nsca = NscaSender(remote_host='1.2.3.4', password='1234', encryption_method=1)
nsca.send_service(status=STATE_OK, host_name='host', service_name='service',
                text_output='output')
nsca.disconnect()
class jflib.send_nsca.AES128Crypter(*args)[source]
CryptoCipher = <Mock name='mock.Cipher.AES' id='139940787457944'>
crypt_id = 14
key_size = 16
class jflib.send_nsca.AES192Crypter(*args)[source]
CryptoCipher = <Mock name='mock.Cipher.AES' id='139940787457944'>
crypt_id = 15
key_size = 24
class jflib.send_nsca.AES256Crypter(*args)[source]
CryptoCipher = <Mock name='mock.Cipher.AES' id='139940787457944'>
crypt_id = 16
key_size = 32
class jflib.send_nsca.BlowFishCrypter(*args)[source]
CryptoCipher = <Mock name='mock.Cipher.Blowfish' id='139940787457384'>
crypt_id = 8
key_size = 56
class jflib.send_nsca.CAST128Crypter(*args)[source]
CryptoCipher = <Mock name='mock.Cipher.CAST' id='139940787986840'>
crypt_id = 4
key_size = 16
class jflib.send_nsca.CAST256Crypter(iv, password, random_generator)[source]
crypt_id = 5
exception jflib.send_nsca.ConfigParseError(filename, lineno, msg)[source]
class jflib.send_nsca.Crypter(iv, password, random_generator)[source]
crypt_id = -1
encrypt(value)[source]
class jflib.send_nsca.CryptoCrypter(*args)[source]
CryptoCipher = <Mock name='mock.Cipher.DES' id='139940787456824'>
crypt_id = -1
encrypt(value)[source]
iv_size = None
key_size = 7
class jflib.send_nsca.DES3Crypter(*args)[source]
CryptoCipher = <Mock name='mock.Cipher.DES3' id='139940787457104'>
crypt_id = 3
key_size = 24
class jflib.send_nsca.DESCrypter(*args)[source]
CryptoCipher = <Mock name='mock.Cipher.DES' id='139940787456824'>
crypt_id = 2
key_size = 8
class jflib.send_nsca.Loki97Crypter(iv, password, random_generator)[source]
crypt_id = 10
class jflib.send_nsca.NscaSender(remote_host, config_path='/etc/send_nsca.cfg', port=5667, timeout=10, send_to_all=True, password='', encryption_method=0)[source]

Send NSCA messages.

Parameters
  • remote_host (str) – host to send to

  • config_path (str) – path to the nsca config file. Usually /etc/send_nsca.cfg. None to disable.

  • port (int) – The port the NSCA server listen to.

  • send_to_all (bool) – If true, will repeat your message to all hosts that match the lookup for remote_hos0

  • password (str) – The NSCA password. Max password length: 512

  • encryption_method (int) – An integer. The NSCA encryption method. The supported encryption methods are: 0 1 2 3 4 8 11 14 15 16’

connect()[source]
disconnect()[source]
parse_config(config_file_object, config_path='')[source]
send_host(host, state, description)[source]
Parameters
  • host (Union[str, bytes]) – Host name to report as

  • state (int) – Integer describing the status

  • description (Union[str, bytes]) – Freeform text, should be under 512b

send_service(host, service, state, description)[source]
Parameters
  • host (Union[str, bytes]) – Host name to report as

  • service (Union[str, bytes]) – Service to report as

  • state (int) – Integer describing the status

  • description (Union[str, bytes]) – Freeform text, should be under 512b

class jflib.send_nsca.NullCrypter(iv, password, random_generator)[source]
crypt_id = 0
encrypt(value)[source]
class jflib.send_nsca.RC2Crypter(*args)[source]
CryptoCipher = <Mock name='mock.Cipher.ARC2' id='139940787457664'>
crypt_id = 11
key_size = 128
class jflib.send_nsca.RC4Crypter(iv, password, random_generator)[source]
crypt_id = 12
class jflib.send_nsca.RC6Crypter(iv, password, random_generator)[source]
crypt_id = 13
class jflib.send_nsca.ThreeWayCrypter(iv, password, random_generator)[source]
crypt_id = 7
class jflib.send_nsca.TwoFishCrypter(iv, password, random_generator)[source]
crypt_id = 9
class jflib.send_nsca.UnsupportedCrypter(iv, password, random_generator)[source]
crypt_id = -1
class jflib.send_nsca.XORCrypter(iv, password, random_generator)[source]
crypt_id = 1
encrypt(value)[source]
class jflib.send_nsca.XTEACrypter(iv, password, random_generator)[source]
crypt_id = 6
jflib.send_nsca.get_random_alphanumeric_bytes(bytesz)[source]
jflib.send_nsca.nsca_critical(host_name, service_name, text_output, remote_host, **kwargs)[source]

Wrapper for the send_nsca() function to easily send a CRITICAL

Parameters
  • host_name (Union[str, bytes]) – Host name to report as

  • service_name (Union[str, bytes]) – Service to report as

  • text_output (Union[str, bytes]) – Freeform text, should be under 512b

  • remote_host (str) – Host name to send to

  • config_path (str) – path to the nsca config file. Usually /etc/send_nsca.cfg. None to disable.

  • port (int) – The port the NSCA server listen to.

  • send_to_all (bool) – If true, will repeat your message to all hosts that match the lookup for remote_hos0

  • password (str) – The NSCA password. Max password length: 512

  • encryption_method (int) – An integer. The NSCA encryption method. The supported encryption methods are: 0 1 2 3 4 8 11 14 15 16’

jflib.send_nsca.nsca_ok(host_name, service_name, text_output, remote_host, **kwargs)[source]

Wrapper for the send_nsca() function to easily send an OK

Parameters
  • host_name (Union[str, bytes]) – Host name to report as

  • service_name (Union[str, bytes]) – Service to report as

  • text_output (Union[str, bytes]) – Freeform text, should be under 512b

  • remote_host (str) – Host name to send to

  • config_path (str) – path to the nsca config file. Usually /etc/send_nsca.cfg. None to disable.

  • port (int) – The port the NSCA server listen to.

  • send_to_all (bool) – If true, will repeat your message to all hosts that match the lookup for remote_hos0

  • password (str) – The NSCA password. Max password length: 512

  • encryption_method (int) – An integer. The NSCA encryption method. The supported encryption methods are: 0 1 2 3 4 8 11 14 15 16’

jflib.send_nsca.nsca_unknown(host_name, service_name, text_output, remote_host, **kwargs)[source]

Wrapper for the send_nsca() function to easily send an UNKNONW

Parameters
  • host_name (Union[str, bytes]) – Host name to report as

  • service_name (Union[str, bytes]) – Service to report as

  • text_output (Union[str, bytes]) – Freeform text, should be under 512b

  • remote_host (str) – Host name to send to

  • config_path (str) – path to the nsca config file. Usually /etc/send_nsca.cfg. None to disable.

  • port (int) – The port the NSCA server listen to.

  • send_to_all (bool) – If true, will repeat your message to all hosts that match the lookup for remote_hos0

  • password (str) – The NSCA password. Max password length: 512

  • encryption_method (int) – An integer. The NSCA encryption method. The supported encryption methods are: 0 1 2 3 4 8 11 14 15 16’

jflib.send_nsca.nsca_warning(host_name, service_name, text_output, remote_host, **kwargs)[source]

Wrapper for the send_nsca() function to easily send a WARNING

Parameters
  • host_name (Union[str, bytes]) – Host name to report as

  • service_name (Union[str, bytes]) – Service to report as

  • text_output (Union[str, bytes]) – Freeform text, should be under 512b

  • remote_host (str) – Host name to send to

  • config_path (str) – path to the nsca config file. Usually /etc/send_nsca.cfg. None to disable.

  • port (int) – The port the NSCA server listen to.

  • send_to_all (bool) – If true, will repeat your message to all hosts that match the lookup for remote_hos0

  • password (str) – The NSCA password. Max password length: 512

  • encryption_method (int) – An integer. The NSCA encryption method. The supported encryption methods are: 0 1 2 3 4 8 11 14 15 16’

jflib.send_nsca.send_nsca(status, host_name, service_name, text_output, remote_host, **kwargs)[source]

Helper function to easily send a NSCA message (wraps .nsca.NscaSender)

Parameters
  • status (int) – Integer describing the status

  • host_name (Union[str, bytes]) – Host name to report as

  • service_name (Union[str, bytes]) – Service to report as

  • text_output (Union[str, bytes]) – Freeform text, should be under 512b

  • remote_host (str) – Host name to send to

  • config_path (str) – path to the nsca config file. Usually /etc/send_nsca.cfg. None to disable.

  • port (int) – The port the NSCA server listen to.

  • send_to_all (bool) – If true, will repeat your message to all hosts that match the lookup for remote_hos0

  • password (str) – The NSCA password. Max password length: 512

  • encryption_method (int) – An integer. The NSCA encryption method. The supported encryption methods are: 0 1 2 3 4 8 11 14 15 16’