Writing graceful timeout for Nagios plugin - monitoring

From Nagios' Plugin Development Guidelines:
Plugins have a very limited runtime - typically 10 sec. As a result, it is very important for plugins to maintain internal code to exit if runtime exceeds a threshold.
All plugins should timeout gracefully, not just networking plugins.
How can I implement a timeout mechanism into my custom plugin? Basically I want my plugin to return a status code 3 - UNKNOWN instead of the default 1 - CRITICAL when the plugin times out, to reduce the number of false positives generated.
EDIT: My plugin is written in Bash.

You can use timeout. Here is example usage:
timeout 15 ping google.com
if [ $? -eq 124 ]; then
echo "UNKNOWN - Time limit exceeded."
exit 3
if
You will get return exit status 124 from timeout when your command don't finish in defined time - 15 sec.

Related

Unable to upload wasm file on terra-station

I developed NFT smart contract based on Cosmwasm for Terra blockchain. It was working well, but when I upgraded cosmwasm-std version from 0.9.2 to 1.0.0-beta8, despite of successful compiling and optimization of source code, storing wasm on chain is invoking error.
My code is based on https://github.com/terran6/nft_on_terra/ and deployed using following command
terrain deploy cw721-base --signer custom_tester_1 --network testnet --set-signer-as-admin
terrain sync-refs
This command made error as follows.
...
Optimizing cw721_base.wasm ...
Creating hashes ...
5401a4be4cccc8c52109391ed3473074941153eecb71d79bdb2fd813fe3a77d9 cw721_base.wasm
Info: sccache stats after build
Compile requests 41
Compile requests executed 25
Cache hits 0
Cache misses 25
Cache misses (Rust) 25
Cache timeouts 0
Cache read errors 0
Forced recaches 0
Cache write errors 0
Compilation failures 0
Cache errors 0
Non-cacheable compilations 0
Non-cacheable calls 16
Non-compilation calls 0
Unsupported compiler calls 0
Average cache write 0.000 s
Average cache read miss 2.733 s
Average cache read hit 0.000 s
Failed distributed compilations 0
Non-cacheable reasons:
crate-type 12
- 4
Cache location Local disk: "/root/.cache/sccache"
Cache size 15 MiB
Max cache size 10 GiB
done
storing wasm bytecode on chain... !
Error: Request failed with status code 400
Response: failed to execute message; message index: 0: Error calling the
VM: Error during static Wasm validation: Wasm contract has unknown
interface_version_* marker export (see
https://github.com/CosmWasm/cosmwasm/blob/main/packages/vm/README.md):
store wasm contract failed: invalid request
Error: Process completed with exit code 1.
This error is pressing me several days. Thanks in advance.

wine fixme wait_for_withdrawn_state window

I am running a Windows execuable (.exe) using wine, in a docker container and I am dumping the graphical interface using xvfb-run. The setup is working but with some fixmes and some errors which I am trying to understand what do they mean.
The most common and fixme is:
002c:fixme:event:wait_for_withdrawn_state window 0x1004a/e00001 wait timed out
0024:fixme:event:wait_for_withdrawn_state window 0x10086/a00003 wait timed out
I found here that it means that:
Your application X Windows are possibly staying in a Withdrawn (aka limbo) state - because Wine isn't drawing to the correct X (Xvfb) Display.
However I do not understand what is this withdrawn state and why wine isn't drawing to the corrcect X. Furthermore the same fixme is present when running wine with xvfb locally without docker.
Thank you!
The whole log from the docker-xvfb-wine setup:
$ xvfb-run --server-num=99 wine my.exe (runs using a run.sh specified by the CMD clause in the dockerfile)
0050:err:ole:StdMarshalImpl_MarshalInterface Failed to create ifstub, hr 0x80004002
0050:err:ole:CoMarshalInterface Failed to marshal the interface {6d5140c1-7436-11ce-8034-00aa006009fa}, hr 0x80004002
0050:err:ole:apartment_get_local_server_stream Failed: 0x80004002
0048:err:ole:StdMarshalImpl_MarshalInterface Failed to create ifstub, hr 0x80004002
0048:err:ole:CoMarshalInterface Failed to marshal the interface {6d5140c1-7436-11ce-8034-00aa006009fa}, hr 0x80004002
0048:err:ole:apartment_get_local_server_stream Failed: 0x80004002
0048:err:ole:start_rpcss Failed to open RpcSs service
002c:fixme:event:wait_for_withdrawn_state window 0x1004a/e00001 wait timed out
wine: configuration in L"/root/.wine" has been updated.
0024:fixme:event:wait_for_withdrawn_state window 0x10086/a00003 wait timed out
0024:fixme:event:wait_for_withdrawn_state window 0x1007c/a00001 wait timed out
X connection to :99 broken (explicit kill or server shutdown).
The log from the xvfb-wine setup (without docker):
$ xvfb-run --server-num=99 wine my.exe
0034:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
0034:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
0048:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
0048:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
0050:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
0050:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
002c:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
002c:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
0024:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
0024:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
00cc:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
00cc:fixme:font:get_name_record_codepage encoding 20 not handled, platform 1.
0024:fixme:font:freetype_set_outline_text_metrics failed to read full_nameW for font L"Ani"!
0024:fixme:event:wait_for_withdrawn_state window 0x20044/c00003 wait timed out
0024:fixme:event:wait_for_withdrawn_state window 0x1007a/c00001 wait timed out
XIO: fatal IO error 11 (Resource temporarily unavailable) on X server ":99"
after 19 requests (19 known processed) with 0 events remaining.
You need to start a window manager, like bspwm.
Xvfb :99 &
export DISPLAY=:99
bspwm &
wine some.exe

Jenkins is spawning a lot of daemon processes and server crashes

I've recently installed Jenkins on a cheap VM on Azure. The specs are very low, since I use this server for testing the setup: 1vCPU & 1GB RAM. There will usually only be 1 build at the same time, with a max. of 3, in very rare occassions.
During the build process from Jenkins quite frequently my server would crash completely and stay so for +- 10 - 15 minutes until being able to be used again.
I checked the processes on the server and this is the result:
The full line is like this:
/etc/alternatives/java -Dcom.sun.akuma.Daemon=daemonized -Djava.awt.headless=true -DJENKINS_HOME=/var/lib/jenkins -jar /usr/lib/jenkins/jenkins.war --logfile=/var/log/jenkins/jenkins.log --webroot=/var/cache/jenkins/war --daemon --httpPort=8080 --debug=5 --handlerCountMax=100 --handlerCountMaxIdle=20
It is the same for every single one of those daemons, not a single parameter is different.
Is this normal behavior, and is this the reason why my server is crashing? Or are my specs just too low for Jenkins to run on to?
Thanks in advance!
EDIT:
My jenkins.log file looks pretty normal except for one NullPointerException that keeps coming back up:
2020-01-08 12:43:17.702+0000 [id=148] WARNING h.ExpressionFactory2$JexlExpression#evaluate: Caught exception evaluating: h.filterDescriptors(it,attrs.descriptors) in /configure. Reason: java.lang.NullPointerException: Descriptor list is null for context 'class hudson.model.Hudson' in thread 'Handling GET /configure from 85.154.65.124 : qtp2085857771-148 Jenkins/configure.jelly GlobalLibraries/config.jelly LibraryConfiguration/config.jelly SCMRetriever/DescriptorImpl/config.jelly MultiSCM/DescriptorImpl/config.jelly'
java.lang.NullPointerException: Descriptor list is null for context 'class hudson.model.Hudson' in thread 'Handling GET /configure from 85.154.65.124 : qtp2085857771-148 Jenkins/configure.jelly GlobalLibraries/config.jelly LibraryConfiguration/config.jelly SCMRetriever/DescriptorImpl/config.jelly MultiSCM/DescriptorImpl/config.jelly'
at hudson.model.DescriptorVisibilityFilter.apply(DescriptorVisibilityFilter.java:73)
...

E121: Undefined Variable: VundleInstalled & E15: Invalid Expression: VundleInstalled == 1 when running VIM

I'm running through the upcase courses and they've introduced me to VIM which, with the help of tmux, is slowly replacing my use of Atom. I've been trying to use some simple plugins using Vundler and every time I run Vim . from my rails directory I get the following errors:
E121: Undefined variable: VundleInstalled
E15: Invalid expression: VundleInstalled == 1
I have been up and down this mean, mean internet and cannot find a solution to this issue.
My ~/.vimrc
1 set number
2 set nocompatible
3 filetype off
4
5 syntax on
6 colorscheme Tomorrow-Night
7
8 set rtp+=~/.vim/bundle/vundle.vim
9 call vundle#begin()
10
11 Plugin 'VundleVim/Vundle.vim'
12 Plugin 'tpope/vim-fugitive'
13 Plugin 'wincent/command-t'
14 Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
15 Plugin 'vim-scripts/L9', {'name': 'newL9'}
16 Plugin 'tpope/vim-rails'
17 Plugin 'tpope/vim-rake'
18 Plugin 'tpope/vim-bundler'
19
20 " Color Schemes
21 Plugin 'chriskempson/tomorrow-theme'
22 Plugin 'flazz/vim-colorschemes'
23 Plugin 'chriskempson/base16-vim'
The error I get occurs any time I try to open a file in VIM. On top of that, when I try and work in VIM I get the following message every time I try and open a directory or run a command:
Error detected while processing FileType Auto commands for "*": │Maximum connections set to 1024
E117: Unknown function: rails#buffer_setup
Any help you could offer would be fantastic. I'm really digging VIM and tmux but I'm also discovering there's a bit of a learning curve to both of them.
Thanks!
Update: I have adjusted any issues with matching file names and, as far as I can tell it's not disrupting functionality. All the same, I would like to figure out why I"m getting this error.

Phantomjs loads pages slowly

I'm new into phantomjs, trying it on a standard centOS server (with httpd etc installed, but no modified settings apart from nameservers set to 8.8.8.8 and 8.8.4.4).
I'm using the default loadspeed.js file (be it renamed). However, page speeds appear to be extremely slow. Here's an example:
$ phantomjs phantomjs.js http://www.google.com/
starting
Loading time 90928 msec
$ phantomjs phantomjs.js http://173.194.67.138/ #(one of google's public ips)
starting
Loading time 30204 msec
When I load any url on the server (such as http://something.be ), loadtime is 141msec:
$ phantomjs phantomjs.js http://something.be
starting
Loading time 141 msec
Does anyone have a clue what causes my connection to be this slow? The connection itself is fine, wget takes seconds to download a file of several MB.
Also, when I run the exact same script on OSX locally for Google, this is the output:
phantomjs phantomjs.js http://google.com/
starting
Loading time 430 msec
Found it - seems like ipv6 was the culprit.
I disabled it temporarily by running the following:
echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6
echo 1 > /proc/sys/net/ipv6/conf/default/disable_ipv6
Testing confirms:
$ phantomjs phantomjs.js http://google.com
starting
Loading time 230 msec
Well, in my case, the page was waiting for some GET requests and was not able to reach the requests' server and it kept waiting for long. I could only figure it out when i used the remote debugger option.
phantomjs --remote-debugger-port=9000 loadspeed.js <some_url>
and inside the loadspeed.js file
page.onResourceRequested = function (req) {
console.log('requested: ' + JSON.stringify(req, undefined, 4));
};
page.onResourceReceived = function (res) {
console.log('received: ' + JSON.stringify(res, undefined, 4));
};
and then loading localhost:9000 in any webkit browser (safari/chrome) and seeing the console logs where i could figure out it was waiting for some failed requests for a long time.
TO BYPASS THIS - REDUCE THE TIMEOUT:
page.settings.resourceTimeout = 3000; //in secs
and things were very quick after that. Hope this helps

Resources