Comments (9)
Hi, would it be possible to use the HTTP headers for this use case?
-A HEADERS, --headers HEADERS
The http headers in JSON format.
So search service could have a X-REQUEST-ID
header, maybe this could work in combination with a random number
Some shells provide a RANDOM env for example:
~/ echo $RANDOM
6358
~/ echo $RANDOM
15365
from nagios-http-json.
That is a good idea! I will try this.
from nagios-http-json.
Unfortunately I cant get it to work :~
echo $RANDOM
works in the shell (rhel8).
I try to access it with:
template Service "generic_cf_health_check" {
import "generic-service"
vars.rand = {{ getenv("RANDOM") }}
vars.http_json_headers = {{ return "{\"Accept\": \"application/json\", \"X-REQUEST-ID\": \"" + macro("$service.vars.rand$") + "\"}" }}
...
But unfortunately Icinga executes it with an empty value.
API-Output of the check execution:
"command": [
"/usr/lib64/nagios/plugins/check_http_json.py",
"-A",
"{\"Accept\": \"application/json\", \"X-REQUEST-ID\": \"\"}",
...
Do you see any flaw in my snipplet?
from nagios-http-json.
In my mind an addition to the check whould be something like this:
import uuid
...
if args.guid:
guid = str(uuid.uuid4())
...
if args.headers:
headers=json.loads(args.headers)
if args.guid:
req.add_header('X-REQUEST-ID', guid)
...
parser.add_argument('-g', '--guid', action='store_true', help='Add GUID to headers.')
from nagios-http-json.
Hi, the $RANDOM might only be available in the Bash
Since you might be using Icinga, you could try this:
https://icinga.com/docs/icinga-2/latest/doc/18-library-reference/#random
from nagios-http-json.
I tried it with RANDOM()
and it works. Unfortunately I got feedback from our developers, with thebresult, that an uuid is explicit needed. An integer is not sufficient. Could you please implement it?
from nagios-http-json.
I'm not 100% sure yet if and how to implement this. My current thoughts:
Headers are definitely the way to go and we already have a flag to set them. This provide the highest degree of flexibility, since users are free to decide if and how to set them. An opinionated uuid
flag could lead to a situation in which another user might want a different (not uuid4) format.
And we already got a lot of CLI flags. Once something is in the plugin we need to support and keep it (unless we deprecate it and break backward compatibility).
Let me think about it.
from nagios-http-json.
@K0nne just for fun I threw together an Icinga DSL function that generates (non RFC 4122 conform) UUID4:
object CheckCommand "random uuid" {
command = [ "/bin/echo" ]
arguments = {
"--uuid" = "$uuid$"
}
vars.uuid = {{
characters = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"]
min = 0
max = len(characters)-1
interval = min-max
uuid = ""
for (var i in range(1, 37, 1)) {
if (i in [9, 14, 19, 24]) {
uuid += "-"
continue
}
uuid += characters[Math.round(Math.abs(min + (Math.random() * interval)))]
}
return uuid
}}
}
from nagios-http-json.
You are right. uuid4 is too strict. Your approach looks fine to me. I think I can get away with this.
Thank you!
from nagios-http-json.
Related Issues (20)
- Support Python 3 HOT 5
- OK results do not show Performance Data HOT 12
- Replace deprecated encodestring HOT 2
- Please add an argument to handle UNKNOWN as WARNING or CRITICAL HOT 5
- Using --key-equals with an empty list returns OK HOT 4
- Bug if array element is 0 HOT 3
- Bytes encoding issue HOT 4
- PERFDATA : nagios status code HOT 1
- Include API Method HOT 2
- translate working curl into correct attributes HOT 3
- Issue when selecting all keys HOT 2
- MicrosoftOnline Authentification HOT 1
- How to parse 0.0 values HOT 1
- 401 Unauthorized should not be OK HOT 2
- key with brackets () HOT 3
- Cannot set verify_mode to CERT_NONE when check_hostname is enabled. HOT 2
- Please add an optional parameter to mitigate unknown to critical HOT 3
- Enhanced plugin output without critical information HOT 7
- Broken Makefile and lint test HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nagios-http-json.