I have created a custom plugin in order to monitor a parameter using Nagios XI. To execute that plugin remotely I must use:
/usr/local/nagios/libexec/check_nrpe -H [IP_ADDR] -c [PLUGIN_NAME] -a [ARGUMENT]
Having made appropriate changes in nrpe.cfg and /etc/sudoers, I could get correct results.
But, I need to provide multiple arguments to the command. What should be the syntax I must use?
I would make it a comment if i though anyone could read it. In my command.cfg I had made this
# 'clear_printqueue' event handler command definition
define command{
command_name clear_printqueue
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -c clear_printqueue -a "/PrinterName:$ARG1$" "/ServiceState:$SERVICESTATE$" "/StateType:$SERVICESTATETYPE$" "/ServiceAttempt:$SERVICEATTEMPT$" "/MaxServiceAttempts:$MAXSERVICEATTEMPTS$"
}
I only have Nagios Core 3.4.4 but I hope this might help. My ini file on the client contained this
clear_printqueue = cscript.exe //T:30 //NoLogo scripts\\lib\\wrapper.vbs scripts\\nagiosClear-PrintQueue.vbs "$ARG1$" "$ARG2$" "$ARG3$" "$ARG4$" "$ARG5$"
$ARG#$ gets passed to the script where it runs. In short I just passed the quoted arguments with spaces in between.
Related
In nagios cfg if I want to pass multi parameters to command, the value is seperated by !
My problem is that the password I'm trying to pass to nagios cfg file contains !, which causing problem for nagios to think it's a separator.
Is there any other way to change seperator or literally change the meaning of ! in password string?
e.g.
define service{
use generic-service
host_name 10.62.85.10
service_description ESXi Hardware Check
check_command check_esxi_hardware!root!Password123!!auto
}
nagios thinks the $ARG1$ is root $ARG2$ is Password123 and $ARG3$ is null
actually the value I want to pass is
$ARG1$ is root $ARG2$ is Password123! and $ARG3$ is auto
First, you should use Nagios user macros for store sensitive information like password. Just look to your Nagios private/resource.cfg file for more information.
Nagios uses ! to separate input arguments in the configuration.
Everything is great until you need to use a ! or $ within one of your variables. At this point you need to escape the special character.
You should use a backslash "\" to do this for the ! and $ characters in your Nagios configuration files, like: \! or \$.
I am trying to make logstash installation work by simply executing the command given in the documentation to echo back what ever typed.But that gives me the following error.
My command
C:\logstash-1.4.0\bin>logstash.bat agent -e 'input{stdin{}}output{stdout{}}'
And the error
Error: Expected one of #, input, filter, output at line 1, column 1 (byte 1) aft
er
You may be interested in the '--configtest' flag which you can
use to validate logstash's configuration before you choose
to restart a running system."
Please help.Thanks in advance!
I am testing with logstash-1.4.0 on linux with this tutorial.
I think it is possible a bug on this version.
For example, I test this command on both linux and window. Everything is ok on linux. But it will occur your error at window!!
bin>logstash agent -e 'input{stdin{}}output{stdout{}}'
For my recommendation, you can write your configuration in a file. For example, save input{stdin{}}output{stdout{}} to a file call "stdin.conf". Then when you start logstash, don't use -e flag, instead use -f and specific your configuration file.
bin>logstash agent -f stdin.conf
Hope this can help you.
Try without quotes
C:\logstash-1.4.0\bin>logstash.bat agent -e input{stdin{}}output{stdout{}}
I get this error when I run -e with --debug. I have to remove -e. Example:
GEM_HOME="/opt/logstash/vendor/bundle/jruby/1.9/" /usr/lib/jvm/java-1.6.0/bin/java -server -Xms765M -Xmx2297M -Djava.io.tmpdir=/opt/logstash/forwarder/tmp/ -Xmx2297M -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -Djava.awt.headless=true -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -jar /opt/logstash/forwarder/vendor/jar/jruby-complete-1.7.11.jar -I/opt/logstash/forwarder/lib /opt/logstash/forwarder/lib/logstash/runner.rb agent -f /opt/logstash/forwarder/etc/conf.d/ -l /opt/logstash/forwarder/log/logstash.log -w 1 --debug
I searched man bash, but couldn't find anything that lists out all current bind -x key bindings. Is there any way I could do that? I tried the following:
$ bind -x '"\C-`":"echo hello"'
# test binding: press CTRL+`
hello
# Binding works!
$ bind -p | grep 'hello'
# no output
$ bind -S
# no output
So, is there any way I could see a list of all bind -x currently active?
Seems like you can use bind -X (new in Bash 4.3):
$ help bind
...
-x keyseq:shell-command Cause SHELL-COMMAND to be executed when
KEYSEQ is entered.
-X List key sequences bound with -x and
associated commands in a form that can be
reused as input.
...
$
The above answer returned empty output on bash 4.3.48 for me. But capital āPā does work:
bind - display all function names (and bindings)
This will only give you bindings to functions:
bind -P
Explanation
-P List current readline function names and bindings.
-p Display readline function names and bindings in such a
way that they can be re-read.
Sample output
set-mark can be found on "\C-#", "\e ".
shell-expand-line can be found on "\e\C-e".
start-kbd-macro can be found on "\C-x(".
tilde-expand can be found on "\e&".
transpose-chars can be found on "\C-t".
transpose-words can be found on "\et".
undo can be found on "\C-x\C-u", "\C-_".
unix-line-discard can be found on "\C-u".
unix-word-rubout can be found on "\C-w".
upcase-word can be found on "\eu".
yank can be found on "\C-y".
yank-last-arg can be found on "\e.", "\e_".
yank-nth-arg can be found on "\e\C-y".
yank-pop can be found on "\ey".
bind - display all string insertions
This will give you bindings for arbitrary keystrokes:
bind -S
-S List key sequences that invoke macros and their values
-s List key sequences that invoke macros and their values
in a form that can be reused as input.
sample output:
\el outputs ls -lrtha --color=always\C-j
\ep outputs pwd\C-j
\er outputs docker rm
\ew outputs wget --no-check-certificate \"\"\e[D
manpage
Since it's surprisingly difficult to find the manpage for it, here it is:
bind [-m keymap] [-lpsvPSVX]
bind [-m keymap] [-q function] [-u function] [-r keyseq]
bind [-m keymap] -f filename
bind [-m keymap] -x keyseq:shell-command
bind [-m keymap] keyseq:function-name
bind readline-command
Display current readline key and function bindings, bind a key
sequence to a readline function or macro, or set a readline
variable. Each non-option argument is a command as it would
appear in .inputrc, but each binding or command must be passed
as a separate argument; e.g., '"\C-x\C-r": re-read-init-file'.
Options, if supplied, have the following meanings:
-m keymap
Use keymap as the keymap to be affected by the subsequent
bindings. Acceptable keymap names are emacs,
emacs-standard, emacs-meta, emacs-ctlx, vi, vi-move,
vi-command, and vi-insert. vi is equivalent to
vi-command; emacs is equivalent to emacs-standard.
-l List the names of all readline functions.
-p Display readline function names and bindings in such a
way that they can be re-read.
-P List current readline function names and bindings.
-s Display readline key sequences bound to macros and the
strings they output in such a way that they can be re-
read.
-S Display readline key sequences bound to macros and the
strings they output.
-v Display readline variable names and values in such a way
that they can be re-read.
-V List current readline variable names and values.
-f filename
Read key bindings from filename.
-q function
Query about which keys invoke the named function.
-u function
Unbind all keys bound to the named function.
-r keyseq
Remove any current binding for keyseq.
-x keyseq:shell-command
Cause shell-command to be executed whenever keyseq is
entered. When shell-command is executed, the shell sets
the READLINE_LINE variable to the contents of the
readline line buffer and the READLINE_POINT variable to
the current location of the insertion point. If the
executed command changes the value of READLINE_LINE or
READLINE_POINT, those new values will be reflected in the
editing state.
-X List all key sequences bound to shell commands and the
associated commands in a format that can be reused as
input.
The return value is 0 unless an unrecognized option is given or
an error occurred.
I have a part of bash script which suppose to do validate the arguments, if it matches then proceed or else exit.
Here is my script
TEMP=`getopt --options b,t:,h,n,v,z: --longoptions batch,targetdir:,help,notar,verbose,zone: --name 'mysql-backup-start' -- "$#"`
if [ $? -ne 0 ]; then
echo "Command Incoorect"
exit 1
fi
mysql-backup-start should take the following arguments: -b, -t, -h, -n, -v, -z --targetdir, --help, --notar, --verbose, and --zone. However, if i pass arguments like -nn, -hh, or --tar it works and it's not supposed to work.
To be more precise what i want, if i execute 'mysql-backup-start' should work, 'mysql- backup-start --notar' should work, 'mysql-backup-start --n' should not work, 'mysql-backup-start --targetdir=/home/backup/mysql' should work, 'mysql-backup-start --targetsdir=/home/backup/mysql' should not work, '--mysql-backup-start --ta=/home/backup/mysql' should not work.
When you pass -nn, getopt just interprets it as if you'd specified -n -n. This is often a valid way to pass arguments - For example, ssh -vvv runs with a much higher verbosity level than ssh -v. In other commands you have options to enable or disable features, and the last option (enable or disable) "wins." This is useful for example if the user has defined an alias like alias grep='grep -H' ("Print the file name for each match."), but wants to override it. To do that she could either run command grep or simply revert the option by running grep -h which is then resolved to grep -H -h.
If you want to check that an option has not been specified more than once (although this is usually not necessary), you should do that later when parsing $TEMP.
--tar should not work - See #tuxuday's comment and man getopt.
I have a shell script application.sh, as follows.
#! /bin/busybox sh
set -o nounset -o errexit
readonly emul_script="/usr/local/bin/emul.sh"
readonly profile="/etc/vendor/profile"
source "${profile}"
_usage() {
cat << EOF
${0} [-d]
-d :debug
EOF
The above script starts a specific application. My question is related to the part starting from _usage, I do not quite understand what it means and cannot see how it is used.
The << is the heredoc construct and cats everything up to the end marker (EOF in this case) to stdout.
The ${0} is the name of the input file and this will print something like the following to stdout:
application.sh [-d]
-d :debug
You are missing the trailing } by the way.
Adding to what trojanfoe says, _usage() is a shell function.
But it is never called, nor is the application itself called, so I suppse that is only part of a script.
The _usage function might be called from ${profile} script that is sourced just above it.
Beware, that you may want to put it before the source line, because, strictly speaking, it has to be defined before it is used.