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.
CryptoCrypter
(*args)[source]¶ -
CryptoCipher
= <Mock name='mock.Cipher.DES' id='139940787456824'>¶
-
crypt_id
= -1¶
-
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.
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 toconfig_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_hos0password (
str
) – The NSCA password. Max password length: 512encryption_method (
int
) – An integer. The NSCA encryption method. The supported encryption methods are: 0 1 2 3 4 8 11 14 15 16’
-
class
jflib.send_nsca.
RC2Crypter
(*args)[source]¶ -
CryptoCipher
= <Mock name='mock.Cipher.ARC2' id='139940787457664'>¶
-
crypt_id
= 11¶
-
key_size
= 128¶
-
-
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
text_output (
Union
[str
,bytes
]) – Freeform text, should be under 512bremote_host (
str
) – Host name to send toconfig_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
text_output (
Union
[str
,bytes
]) – Freeform text, should be under 512bremote_host (
str
) – Host name to send toconfig_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
text_output (
Union
[str
,bytes
]) – Freeform text, should be under 512bremote_host (
str
) – Host name to send toconfig_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
text_output (
Union
[str
,bytes
]) – Freeform text, should be under 512bremote_host (
str
) – Host name to send toconfig_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 statustext_output (
Union
[str
,bytes
]) – Freeform text, should be under 512bremote_host (
str
) – Host name to send toconfig_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’