New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NSCP API check plugin for NSClient++ HTTP API #5239

Merged
merged 1 commit into from Jun 13, 2017

Conversation

Projects
None yet
3 participants
@dnsmichi
Member

dnsmichi commented May 10, 2017

Tasks:

  • Parameter naming and NSClient++ API setup
  • Documentation for ITL and Distributed Monitoring chapters
  • Build and runtime test on Linux/Unix
  • Build and runtime test on Windows
  • Package updates (new file)

Tests

  • Linux
michi@mbmif ~/coding/icinga/icinga2 (feature/check_nscp-4721=) $ /usr/local/icinga2/sbin/check_nscp_api --host 10.0.10.148 --password icinga --query check_cpu --arguments show-all warning='load>40' critical='load>30'
check_cpu OK: 5m: 0%, 1m: 0%, 5s: 0% | 'total 5m'=0%;40;30 'total 1m'=0%;40;30 'total 5s'=0%;40;30
  • Windows

screen shot 2017-06-13 at 14 08 14

refs #4721

@dnsmichi dnsmichi self-assigned this May 10, 2017

@dnsmichi dnsmichi changed the title from WIP: Add nscp check plugin for NSClient++ REST API to WIP: Add nscp api check plugin for NSClient++ REST API Jun 12, 2017

@dnsmichi

This comment has been minimized.

Show comment
Hide comment
@dnsmichi

dnsmichi Jun 12, 2017

Member

Some additional notes for newer NSCP versions:

  • a global allowed_hosts overrules a WEBServer specific allowed_hosts setting.
  • it is possible to edit the configuration inside the web frontend inkl reload
  • the error log inside the web frontend is very important to debug the plugin's 403 unknown return state

screen shot 2017-06-12 at 19 55 31

Review

  • renamed the plugin to check_nscp_api
  • renamed --passwd to --password
  • corrected docs, code, etc. - whatever I've seen, did not deeply look into any phrasing
  • started testing against a current NSClient++ instance
  • squashed all commits and my review into a single commit

Tests

michi@mbmif ~/coding/icinga/icinga2 (feature/check_nscp-4721 *<>) $ /usr/local/icinga2/sbin/check_nscp_api --host 192.168.2.108 --password icinga --query check_cpu --debug
Sending request to 'http://192.168.2.108:8443/query/check_cpu'
Received answer
	HTTP code: 200
	HTTP message: ''
JSON Body:
{
	header = {
		source_id = ""
	}
	payload = [ {
		command = "check_cpu"
		lines = [ {
			message = "OK: CPU load is ok."
			perf = [ {
				alias = "total 5m"
				int_value = {
					critical = 90.000000
					unit = "%"
					value = 0.000000
					warning = 80.000000
				}
			}, {
				alias = "total 1m"
				int_value = {
					critical = 90.000000
					unit = "%"
					value = 18.000000
					warning = 80.000000
				}
			}, {
				alias = "total 5s"
				int_value = {
					critical = 90.000000
					unit = "%"
					value = 15.000000
					warning = 80.000000
				}
			} ]
		} ]
		result = "OK"
	} ]
}
check_cpu OK: CPU load is ok. | 'total 5m'=0%;80;90 'total 1m'=18%;80;90 'total 5s'=15%;80;90
michi@mbmif ~/coding/icinga/icinga2 (feature/check_nscp-4721 *<>) $ /usr/local/icinga2/sbin/check_nscp_api --host 192.168.2.108 --password icinga --query check_drivesize --arg drive=C --debug
Sending request to 'http://192.168.2.108:8443/query/check_drivesize?drive=C'
Received answer
	HTTP code: 200
	HTTP message: ''
JSON Body:
{
	header = {
		source_id = ""
	}
	payload = [ {
		command = "check_drivesize"
		lines = [ {
			message = "OK All 1 drive(s) are ok"
			perf = [ {
				alias = "C: used"
				float_value = {
					critical = 49.958786
					maximum = 55.509762
					minimum = 0.000000
					unit = "GB"
					value = 41.409168
					warning = 44.407809
				}
			}, {
				alias = "C: used %"
				float_value = {
					critical = 90.000000
					maximum = 100.000000
					minimum = 0.000000
					unit = "%"
					value = 75.000000
					warning = 80.000000
				}
			} ]
		} ]
		result = "OK"
	} ]
}
check_drivesize OK All 1 drive(s) are ok | 'C: used'=41.409168GB;44.407809;49.958786;0;55.509762 'C: used %'=75%;80;90;0;100

TODO

More tests and configuration. There's probably two CheckCommands of check_nscp_api - one with the exe suffix and one for Linux. The plugin happily runs on Linux and is installed into /sbin.

Member

dnsmichi commented Jun 12, 2017

Some additional notes for newer NSCP versions:

  • a global allowed_hosts overrules a WEBServer specific allowed_hosts setting.
  • it is possible to edit the configuration inside the web frontend inkl reload
  • the error log inside the web frontend is very important to debug the plugin's 403 unknown return state

screen shot 2017-06-12 at 19 55 31

Review

  • renamed the plugin to check_nscp_api
  • renamed --passwd to --password
  • corrected docs, code, etc. - whatever I've seen, did not deeply look into any phrasing
  • started testing against a current NSClient++ instance
  • squashed all commits and my review into a single commit

Tests

michi@mbmif ~/coding/icinga/icinga2 (feature/check_nscp-4721 *<>) $ /usr/local/icinga2/sbin/check_nscp_api --host 192.168.2.108 --password icinga --query check_cpu --debug
Sending request to 'http://192.168.2.108:8443/query/check_cpu'
Received answer
	HTTP code: 200
	HTTP message: ''
JSON Body:
{
	header = {
		source_id = ""
	}
	payload = [ {
		command = "check_cpu"
		lines = [ {
			message = "OK: CPU load is ok."
			perf = [ {
				alias = "total 5m"
				int_value = {
					critical = 90.000000
					unit = "%"
					value = 0.000000
					warning = 80.000000
				}
			}, {
				alias = "total 1m"
				int_value = {
					critical = 90.000000
					unit = "%"
					value = 18.000000
					warning = 80.000000
				}
			}, {
				alias = "total 5s"
				int_value = {
					critical = 90.000000
					unit = "%"
					value = 15.000000
					warning = 80.000000
				}
			} ]
		} ]
		result = "OK"
	} ]
}
check_cpu OK: CPU load is ok. | 'total 5m'=0%;80;90 'total 1m'=18%;80;90 'total 5s'=15%;80;90
michi@mbmif ~/coding/icinga/icinga2 (feature/check_nscp-4721 *<>) $ /usr/local/icinga2/sbin/check_nscp_api --host 192.168.2.108 --password icinga --query check_drivesize --arg drive=C --debug
Sending request to 'http://192.168.2.108:8443/query/check_drivesize?drive=C'
Received answer
	HTTP code: 200
	HTTP message: ''
JSON Body:
{
	header = {
		source_id = ""
	}
	payload = [ {
		command = "check_drivesize"
		lines = [ {
			message = "OK All 1 drive(s) are ok"
			perf = [ {
				alias = "C: used"
				float_value = {
					critical = 49.958786
					maximum = 55.509762
					minimum = 0.000000
					unit = "GB"
					value = 41.409168
					warning = 44.407809
				}
			}, {
				alias = "C: used %"
				float_value = {
					critical = 90.000000
					maximum = 100.000000
					minimum = 0.000000
					unit = "%"
					value = 75.000000
					warning = 80.000000
				}
			} ]
		} ]
		result = "OK"
	} ]
}
check_drivesize OK All 1 drive(s) are ok | 'C: used'=41.409168GB;44.407809;49.958786;0;55.509762 'C: used %'=75%;80;90;0;100

TODO

More tests and configuration. There's probably two CheckCommands of check_nscp_api - one with the exe suffix and one for Linux. The plugin happily runs on Linux and is installed into /sbin.

@dnsmichi

This comment has been minimized.

Show comment
Hide comment
@dnsmichi

dnsmichi Jun 13, 2017

Member
  • Renamed arg to arguments to keep in line with other command line parameters.
  • Some documentation updates

TODOs

  • arguments don't support nscp thresholds
$ /usr/local/icinga2/sbin/check_nscp_api --host 10.0.10.148 --password icinga --query check_cpu --arguments show-all warning='load > 75' critical='load > 90' --debug
the argument ('warning=load > 75') for option '--arguments' is invalid
Member

dnsmichi commented Jun 13, 2017

  • Renamed arg to arguments to keep in line with other command line parameters.
  • Some documentation updates

TODOs

  • arguments don't support nscp thresholds
$ /usr/local/icinga2/sbin/check_nscp_api --host 10.0.10.148 --password icinga --query check_cpu --arguments show-all warning='load > 75' critical='load > 90' --debug
the argument ('warning=load > 75') for option '--arguments' is invalid
@dnsmichi

This comment has been minimized.

Show comment
Hide comment
@dnsmichi

dnsmichi Jun 13, 2017

Member

It is a matter of whitespaces in the threshold arguments, if you remove them, the parser works fine.

check_nscp_api --host 10.0.10.148 --password icinga --query check_cpu --arguments show-all warning='load>40' critical='load>30' --debug
Sending request to 'https://10.0.10.148:8443/query/check_cpu?critical=load%3E30&show-all&warning=load%3E40'
Received answer
	HTTP code: 200
	HTTP message: ''
JSON Body:
{
	header = {
		source_id = ""
	}
	payload = [ {
		command = "check_cpu"
		lines = [ {
			message = "CRITICAL: critical(5m: 48%, 1m: 36%), 5s: 0%"
			perf = [ {
				alias = "total 5m"
				int_value = {
					critical = 30.000000
					unit = "%"
					value = 48.000000
					warning = 40.000000
				}
			}, {
				alias = "total 1m"
				int_value = {
					critical = 30.000000
					unit = "%"
					value = 36.000000
					warning = 40.000000
				}
			}, {
				alias = "total 5s"
				int_value = {
					critical = 30.000000
					unit = "%"
					value = 0.000000
					warning = 40.000000
				}
			} ]
		} ]
		result = "CRITICAL"
	} ]
}
check_cpu CRITICAL: critical(5m: 48%, 1m: 36%), 5s: 0% | 'total 5m'=48%;40;30 'total 1m'=36%;40;30 'total 5s'=0%;40;30
Member

dnsmichi commented Jun 13, 2017

It is a matter of whitespaces in the threshold arguments, if you remove them, the parser works fine.

check_nscp_api --host 10.0.10.148 --password icinga --query check_cpu --arguments show-all warning='load>40' critical='load>30' --debug
Sending request to 'https://10.0.10.148:8443/query/check_cpu?critical=load%3E30&show-all&warning=load%3E40'
Received answer
	HTTP code: 200
	HTTP message: ''
JSON Body:
{
	header = {
		source_id = ""
	}
	payload = [ {
		command = "check_cpu"
		lines = [ {
			message = "CRITICAL: critical(5m: 48%, 1m: 36%), 5s: 0%"
			perf = [ {
				alias = "total 5m"
				int_value = {
					critical = 30.000000
					unit = "%"
					value = 48.000000
					warning = 40.000000
				}
			}, {
				alias = "total 1m"
				int_value = {
					critical = 30.000000
					unit = "%"
					value = 36.000000
					warning = 40.000000
				}
			}, {
				alias = "total 5s"
				int_value = {
					critical = 30.000000
					unit = "%"
					value = 0.000000
					warning = 40.000000
				}
			} ]
		} ]
		result = "CRITICAL"
	} ]
}
check_cpu CRITICAL: critical(5m: 48%, 1m: 36%), 5s: 0% | 'total 5m'=48%;40;30 'total 1m'=36%;40;30 'total 5s'=0%;40;30
@dnsmichi

This comment has been minimized.

Show comment
Hide comment
@dnsmichi

dnsmichi Jun 13, 2017

Member

The plugin should installed to PluginDir either way, no matter if Windows or Linux. That requires a change in our build scripts on macOS @gunnarbeutner by setting ICINGA2_PLUGINDIR to an explicit path.

export I2_DEBUG="-DCMAKE_BUILD_TYPE=Debug -DICINGA2_UNITY_BUILD=OFF -DICINGA2_WITH_STUDIO=ON -DCMAKE_INSTALL_PREFIX=/usr/local/icinga2 -DOPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include -DOPENSSL_SSL_LIBRARY=/usr/local/opt/openssl/lib/libssl.dylib -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl/lib/libcrypto.dylib -DICINGA2_PLUGINDIR=/usr/local/sbin"
export I2_RELEASE="-DCMAKE_BUILD_TYPE=RelWithDebInfo -DICINGA2_WITH_TESTS=ON -DICINGA2_UNITY_BUILD=ON -DICINGA2_WITH_STUDIO=ON -DCMAKE_INSTALL_PREFIX=/usr/local/icinga2 -DOPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include -DOPENSSL_SSL_LIBRARY=/usr/local/opt/openssl/lib/libssl.dylib -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl/lib/libcrypto.dylib -DICINGA2_PLUGINDIR=/usr/local/sbin"
-- Installing: /usr/local/sbin/check_nscp_api

Once adopted, the CheckCommand definition is the same on Linux and Windows inside the ITL. That was my initial goal.

Member

dnsmichi commented Jun 13, 2017

The plugin should installed to PluginDir either way, no matter if Windows or Linux. That requires a change in our build scripts on macOS @gunnarbeutner by setting ICINGA2_PLUGINDIR to an explicit path.

export I2_DEBUG="-DCMAKE_BUILD_TYPE=Debug -DICINGA2_UNITY_BUILD=OFF -DICINGA2_WITH_STUDIO=ON -DCMAKE_INSTALL_PREFIX=/usr/local/icinga2 -DOPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include -DOPENSSL_SSL_LIBRARY=/usr/local/opt/openssl/lib/libssl.dylib -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl/lib/libcrypto.dylib -DICINGA2_PLUGINDIR=/usr/local/sbin"
export I2_RELEASE="-DCMAKE_BUILD_TYPE=RelWithDebInfo -DICINGA2_WITH_TESTS=ON -DICINGA2_UNITY_BUILD=ON -DICINGA2_WITH_STUDIO=ON -DCMAKE_INSTALL_PREFIX=/usr/local/icinga2 -DOPENSSL_INCLUDE_DIR=/usr/local/opt/openssl/include -DOPENSSL_SSL_LIBRARY=/usr/local/opt/openssl/lib/libssl.dylib -DOPENSSL_CRYPTO_LIBRARY=/usr/local/opt/openssl/lib/libcrypto.dylib -DICINGA2_PLUGINDIR=/usr/local/sbin"
-- Installing: /usr/local/sbin/check_nscp_api

Once adopted, the CheckCommand definition is the same on Linux and Windows inside the ITL. That was my initial goal.

@dnsmichi

This comment has been minimized.

Show comment
Hide comment
@dnsmichi

dnsmichi Jun 13, 2017

Member

Still not satisfied with the documentation, work in progress.

Member

dnsmichi commented Jun 13, 2017

Still not satisfied with the documentation, work in progress.

@dnsmichi dnsmichi added this to the 2.7.0 milestone Jun 13, 2017

@dnsmichi dnsmichi added the Plugins label Jun 13, 2017

@dnsmichi dnsmichi changed the title from WIP: Add nscp api check plugin for NSClient++ REST API to Add NSCP API check plugin for NSClient++ HTTP API Jun 13, 2017

@dnsmichi

This comment has been minimized.

Show comment
Hide comment
@dnsmichi

dnsmichi Jun 13, 2017

Member

Package build local test as workaround for missing branch pipeline:

docker run -ti centos bash

yum -y install rpmdevtools git
cd
rpmdev-setuptree
git clone https://github.com/icinga/icinga2
cd icinga2/
git checkout feature/check_nscp-4721
cp icinga2.spec ../rpmbuild/SPECS/
git archive --format=tar --prefix=icinga2-2.6.3/ HEAD | gzip >v2.6.3.tar.gz
cp v2.6.3.tar.gz ../rpmbuild/SOURCES/
cd ../rpmbuild/
yum-builddep -y SPECS/icinga2.spec
rpmbuild -ba SPECS/icinga2.spec
Member

dnsmichi commented Jun 13, 2017

Package build local test as workaround for missing branch pipeline:

docker run -ti centos bash

yum -y install rpmdevtools git
cd
rpmdev-setuptree
git clone https://github.com/icinga/icinga2
cd icinga2/
git checkout feature/check_nscp-4721
cp icinga2.spec ../rpmbuild/SPECS/
git archive --format=tar --prefix=icinga2-2.6.3/ HEAD | gzip >v2.6.3.tar.gz
cp v2.6.3.tar.gz ../rpmbuild/SOURCES/
cd ../rpmbuild/
yum-builddep -y SPECS/icinga2.spec
rpmbuild -ba SPECS/icinga2.spec
@dnsmichi

This comment has been minimized.

Show comment
Hide comment
@dnsmichi

dnsmichi Jun 13, 2017

Member

Disabling unity builds inside docker helps with low ram usage.

         -DICINGA2_GROUP=%{icinga_group} \
         -DICINGA2_UNITY_BUILD=OFF \
         -DICINGA2_COMMAND_GROUP=%{icingacmd_group}"
[root@1282731fd11a rpmbuild]# rpm2cpio RPMS/x86_64/icinga2-bin-2.6.3-1.el7.centos.x86_64.rpm | cpio -ivd
./usr/lib64/icinga2/sbin
./usr/lib64/icinga2/sbin/icinga2
./usr/lib64/nagios/plugins/check_nscp_api
Member

dnsmichi commented Jun 13, 2017

Disabling unity builds inside docker helps with low ram usage.

         -DICINGA2_GROUP=%{icinga_group} \
         -DICINGA2_UNITY_BUILD=OFF \
         -DICINGA2_COMMAND_GROUP=%{icingacmd_group}"
[root@1282731fd11a rpmbuild]# rpm2cpio RPMS/x86_64/icinga2-bin-2.6.3-1.el7.centos.x86_64.rpm | cpio -ivd
./usr/lib64/icinga2/sbin
./usr/lib64/icinga2/sbin/icinga2
./usr/lib64/nagios/plugins/check_nscp_api
@dnsmichi

This comment has been minimized.

Show comment
Hide comment
@dnsmichi

dnsmichi Jun 13, 2017

Member

I'm satisfied, and it is all set for v2.7. @gunnarbeutner & @Crunsher agreed today.

Member

dnsmichi commented Jun 13, 2017

I'm satisfied, and it is all set for v2.7. @gunnarbeutner & @Crunsher agreed today.

@dnsmichi dnsmichi merged commit c6b375d into master Jun 13, 2017

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@TheFlyingCorpse

This comment has been minimized.

Show comment
Hide comment
@TheFlyingCorpse

TheFlyingCorpse Jun 13, 2017

Contributor

<3

Contributor

TheFlyingCorpse commented Jun 13, 2017

<3

@dnsmichi dnsmichi deleted the feature/check_nscp-4721 branch Jun 20, 2017

dnsmichi added a commit that referenced this pull request Aug 15, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment