Giter Site home page Giter Site logo

Comments (9)

martialblog avatar martialblog commented on July 27, 2024

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.

K0nne avatar K0nne commented on July 27, 2024

That is a good idea! I will try this.

from nagios-http-json.

K0nne avatar K0nne commented on July 27, 2024

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.

K0nne avatar K0nne commented on July 27, 2024

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.

martialblog avatar martialblog commented on July 27, 2024

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.

K0nne avatar K0nne commented on July 27, 2024

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.

martialblog avatar martialblog commented on July 27, 2024

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.

martialblog avatar martialblog commented on July 27, 2024

@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.

K0nne avatar K0nne commented on July 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.