executing check_nrpe from iCinga2 - monitoring

I am trying to execute nrpe plugin from my iCinga server like this
/usr/local/nagios/libexec/check_nrpe -H <host> -c \
'nrpe_check_traffic_status' -a '2' '3' -p <port>
I have made some print in plugin this is the result
>>opt>> -w >> arg 2
>>opt>> -c >> arg -p ### THIS LINE IS ERROR ###
Threshold values should be numerical
It is not executed properly, It sends -p as second argument instead of 3 to remote nrpe
But same working when I give like this
/usr/local/nagios/libexec/check_nrpe -H <host> -c \
'nrpe_check_traffic_status' -p <port>-a '2' '3'
Result
>>opt>> -w >> arg 2
>>opt>> -c >> arg 3
TRAFFIC STATUS OK;
Did anyone faced this issue? Is there any solution for this?
Or is there any way to change this argument position in iCinga2 configuration?
Note: I have tried changing argument parameter up/down in commands.conf file, no use.

Finally I found a way to configure arguments position while executing from icinga,
Here is more info: iCinga_Doc
arguments = {
"-X" = {
value = "$x_val$"
key = "-Xnew" /* optional, set a new key identifier */
description = "My plugin requires this argument for doing X."
required = false /* optional, no error if not set */
skip_key = false /* always use "-X <value>" */
set_if = "$have_x$" /* only set if variable defined and resolves to a numeric value. String values are not supported */
order = -1 /* first position */
repeat_key = true /* if `value` is an array, repeat the key as parameter: ... 'key' 'value[0]' 'key' 'value[1]' 'key' 'value[2]' ... */
}
"-Y" = {
value = "$y_val$"
description = "My plugin requires this argument for doing Y."
required = false /* optional, no error if not set */
skip_key = true /* don't prefix "-Y" only use "<value>" */
set_if = "$have_y$" /* only set if variable defined and resolves to a numeric value. String values are not supported */
order = 0 /* second position */
repeat_key = false /* if `value` is an array, do not repeat the key as parameter: ... 'key' 'value[0]' 'value[1]' 'value[2]' ... */
}
}
Added order and repeat_key=false to my command.conf file. This solve my problem!!

Related

How to convert a jenkins boolean param into all caps "TRUE" or "FALSE" string parameter?

I have the following defined in my multibranch declarative pipeline:
steps {
script {
BUILD_PROD_FLAG = sh(returnStdout: true, script: "[ ${BUILD_PROD} = true ] && echo TRUE || echo FALSE; ").trim()
BUILD_PROD_FLAG_SECOND = expression { if (params.BUILD_PROD) { return "TRUE" } else { return "FALSE" } }
}
sh "echo alternative way to get true/false set (want this to say FALSE): ${BUILD_FLAG_SECOND}"
}
The first variable BUILD_PROD_FLAG works fine.
I would like to eliminate the convoluted bash spawning employed there.
The second one does not work:
Multibranch_PR-1#tmp/durable-212f3652/script.sh: 1: /home/ubuntu/workspace/s_InsightCamera_Multibranch_PR-1#tmp/durable-212f3652/script.sh: Syntax error: "(" unexpected
This apparently is due to
Which I am not able to comprehend.
When the expression block is removed it fails to parse:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 67: unexpected token: if # line 67, column 57.
BUILD_FLAG_SECOND = if (params
^
1 error
And when I tried something else that is different:
BUILD_FLAG_SECOND = expression { return params.BUILD_PROD ? "TRUE" : "FALSE" }
I get the same Syntax error: "(" unexpected error. I don't understand why this is a .sh shell script, by the way.
Update: OK I think I get why it's a .sh, that's just the sh clause near the bottom that I have.
I also thought I solved it because I did neglect to quote things for the shell, but with the adjustment:
sh "echo 'alternative way to get true/false set (want this to say FALSE):' ${BUILD_FLAG_SECOND}"
Still the same error:
I think it is for real trying to interpolate the string #expression(<anonymous>=org.jenkinsci.plugins.workflow.cps.CpsClosure2#4a286654) in place of the BUILD_FLAG_SECOND variable...
Are you ready for the epic facepalm that is the solution?
BUILD_FLAG_SECOND = params.BUILD_PROD ? "TRUE" : "FALSE"
That's it.

Terraform helm set value of type array

When I set an array value for a helm_release resource from my TF code like below:
set {
name = "ObjectIds"
value = "{${join(",", local.rbac_config.group_oid_list)}}"
}
My TF Plan shows the value being passed like whats shown below:
+ set {
+ name = "ObjectIds"
+ value = "{"Id1-xxxxxxxxxxx,Id2-yyyyyyyyyyyyyyyyyyy,Id3-zzzzzzzzzzzzzzzz"}"
}
Why I need the format to be like this?
When the helm chart is installed manually from the command line using helm install, it throws an error if I specify --set ObjectIds={Id1-xxxxxxxx,Id2-yyyyyyyy,Id3-zzzzzz}
Helm Error: Error: This command needs 2 arguments: release name, chart path
Fix: It works just fine when I specify --set ObjectIds={"Id1-xxxxxxxx,Id2-yyyyyyyy,Id3-zzzzzz"}.
So I want the Terraform code to parse the value as value = "{"Id1-xxxxxxxx,Id2-yyyyyyyy,Id3-zzzzzz"}" instead of value = "{Id1-xxxxxxxx,Id2-yyyyyyyy,Id3-zzzzzz}"
Things I have tried:
1. Doesn't works:
set {
name = "ObjectIds"
value = "{\"${join(",", local.rbac_config.group_oid_list)}\"}"
}
Failue/Error : TF Plan parses the value as
+ value = "{\"Id1-xxxxxxxx,Id2-yyyyyyyy,Id3-zzzzzz\"}"
2. Doesn't works:
set {
name = "ObjectIds"
value = format("\"%s\"", join(",", local.rbac_config.group_oid_list))
}
Failue/Error : TF Plan parses the value as
+ value = "{\"Id1-xxxxxxxx,Id2-yyyyyyyy,Id3-zzzzzz\"}"
Any suggestions how do I get this working?
I know it is old question, but when you have variables you can use dynamic set:
dynamic set {
for_each = var.sample_array
content {
name = "object[${set.key}]"
value = set.value
}
}

How to pass required arguments in Google colab (Notebook)

I use google colab for execution.
In the following code, as all the arguments are passed by default. I can pass the args as an empty list, which can be seen from the last line:
DEFAULT_ENV_NAME = "PongNoFrameskip-v4"
MEAN_REWARD_BOUND = 19.5
parser.add_argument("--cuda", default=True, action="store_true", help="Enable cuda")
parser.add_argument("--env", default=DEFAULT_ENV_NAME,
help="Name of the environment, default=" + DEFAULT_ENV_NAME)
parser.add_argument("--reward", type=float, default=MEAN_REWARD_BOUND,
help="Mean reward boundary for stop of training, default=%.2f" % MEAN_REWARD_BOUND)
args = parser.parse_args(args = [])
when I use print(args) I got:
Namespace(cuda=True, env='PongNoFrameskip-v4', reward=19.5)
Also when I execute the following code:
DEFAULT_ENV_NAME = "PongNoFrameskip-v4"
parser.add_argument("-m", "--model", required=True, help="Model file to load")
parser.add_argument("-e", "--env", default=DEFAULT_ENV_NAME,
help="Environment name to use, default=" + DEFAULT_ENV_NAME)
parser.add_argument("-r", "--record", help="Directory to store video recording")
parser.add_argument("--no-visualize", default=True, action='store_false', dest='visualize',
help="Disable visualization of the game play")
args = parser.parse_args(args=['dqn_model'])
I am getting errors in syntax, which is because of the last line. I need to send required values for model argument (say dqn_model).
What is the correct syntax for passing the arguments?
I tried the following which gave me errors:
args = parser.parse_args(args=['dqn_model'])
args = parser.parse_args(args=[model='dqn_model'])
args = parser.parse_args(args=[m='dqn_model'])
this worked out for me
use :
args = argparse.Namespace(cuda="Argument=required",env="PongNoFrameskip-v4",reward=19.5)
make sure you have added all the argument keys with their respective value.

hmac authentication in vcl

I am trying to authenticate URL using hamc. I can do the following to verify.My question is how do I parse the URL to extract only part of the URL excluding the hmac parameter. I tried using local variables in vcl but it threw an error.
Any suggestions on how to extract the hmac value and URL query parameters as shown below.
http://localhost/zzz/?q1=xxx&q2=yyy&hmac=hash
if (digest.hmac_md5("key", "q1=xxx&q2=yyy") != "value")
{
return (synth(401, digest.hmac_md5("key", "http://localhost/zzz/?q1=xxx&q2=yyy")));
}
Thanks
You'll want to use the [querystring][1] vmod. As far as I know it does not come pre-packaged, so you will need to build it but it should do exactly what you need.
With that you can define regexes/static values to match querystring arguments, and then filter those out or in.
there is no need for a external plugin in that case you can just strip out the hmac=XXX query string parameter, from req.url and store the result in a new variable req.http.url_without_hmac and req.http.hmac to the digest.hmac_md5
see a sample test case:
varnishtest "Strip query parameter"
server s1 {
rxreq
txresp
rxreq
txresp
} -start
varnish v1 -vcl+backend {
import std;
sub vcl_recv {
# Strip out HMAC parameter
# get only the query string, ignore uri
set req.http.qs = regsuball(req.url, ".*\?(.*?)$", "?\1");
# strip hmac= from the qs
set req.http.url_without_hmac = regsuball(req.http.qs,"\?hmac=[^&]+$",""); # strips when QS = "?hmac=AAA"
set req.http.url_without_hmac = regsuball(req.http.url_without_hmac,"\?hmac=[^&]+&","?"); # strips when QS = "?hmac=AAA&foo=bar"
set req.http.url_without_hmac = regsuball(req.http.url_without_hmac,"&hmac=[^&]+",""); # strips when QS = "?foo=bar&hmac=AAA" or QS = "?foo=bar&hmac=AAA&bar=baz"
# remove the leading ? from the url_without_hmac
set req.http.url_without_hmac = regsuball(req.http.url_without_hmac,"^\?(.*)$", "\1");
# extract the hmac= value from the req.http.qs
set req.http.hmac = regsuball(req.http.qs, ".*[?&]hmac=([^&]*).*", "\1");
# NOW USE req.http.url_without_hmac for your digest validation and req.http.hmac as the value
}
sub vcl_deliver {
set resp.http.url_without_hmac = req.http.url_without_hmac;
set resp.http.hmac = req.http.hmac;
}
} -start
client c1 {
txreq -url "/1?a=1&hmac=2&b=1"
rxresp
expect resp.http.url_without_hmac == "a=1&b=1"
expect resp.http.hmac == "2"
} -run
client c2 {
txreq -url "/1?hmac=hello&a=1&b=1"
rxresp
expect resp.http.url_without_hmac == "a=1&b=1"
expect resp.http.hmac == "hello"
} -run

Youtube API returns wrong value

This is a part of my code:
$key = 'XXX';
function check_video($id, $url) {
$x = get_data('https://www.googleapis.com/youtube/v3/videos?part=status&id='.$url.'&key='.$key);
$x = json_decode($x, true);
if($x['items'][0]['status']['embeddable'] == true){
echo "$id = TRUE --- ";
}else{
echo "$id = FALSE --- ";
}
}
check_video(1, '9bZkp7q19f0');
The function should check if the video is embeddable and then simply echo true or false but it keeps printing "1 = FALSE --- " even though a video is embeddable.
Example of video: http://i.gyazo.com/7a84e78cc665ca4920cef18e341f09b6.png
First, in your code above the variable $key in function check_video() is undefined. The variable $key has to be defined in the function or passed in. If it's just a simple copy/paste snafu then continue:
I don't see the definition for function get_code() so I'll assume it's a simple cURL wrapper.
Second, put the finished url into your browser and see if it works.
https://www.googleapis.com/youtube/v3/videos?part=status&id=9bZkp7q19f0&key=YOUR_KEY
Third, put a print_r($x) after json_decode() to see if the YouTube API is returning an error because of something in the get_code() function (like a timeout). You should check for an error regardless.
For me it worked fine.

Resources