hyperjumptech / monika

Monika is a command line application to monitor every part of your web app using a simple YAML configuration file. Get alert not only when your site is down but also when it's slow.
https://monika.hyperjump.tech
MIT License
605 stars 67 forks source link

Feat: Add custom user agent for Monika #1300

Closed dennypradipta closed 4 months ago

dennypradipta commented 5 months ago

Monika Pull Request (PR)

What feature/issue does this PR add

This PR adds custom user agent when probing websites, and will fixes #1292

How did you implement / how did you fix it

  1. Add logic for handling user agents from config
  2. Add default value for user agent
  3. Add flag for user agent

How to test

  1. Create a simple fastify server:
    
    // Import the framework and instantiate it
    import Fastify from "fastify";

const fastify = Fastify({ logger: { serializers: { req(req) { console.log(req.headers["user-agent"]);

    return {
      userAgent: req.headers["user-agent"],
    };
  },
},

}, });

// Declare a route fastify.get("/", async function handler(request, reply) { return { hello: "world" }; });

// Run the server! try { await fastify.listen({ port: 3000 }); } catch (err) { fastify.log.error(err); process.exit(1); }


2. Run the server
3. Run Monika pointing to the local server
4. Pay attention to the user agent

## Video
https://github.com/hyperjumptech/monika/assets/16670475/67920681-af24-47e2-8117-a6c67c7cf972
dennypradipta commented 5 months ago

Still verifying whether if the Docker version uses the custom user agent.

haricnugraha commented 5 months ago

I just remembered Monika has getContext().userAgent. The value is @hyperjumptech/monika/1.20.2 (darwin-x64) node-20.11.0.

dennypradipta commented 4 months ago

I just remembered Monika has getContext().userAgent. The value is @hyperjumptech/monika/1.20.2 (darwin-x64) node-20.11.0.

Thanks for the tip! It works flawlessly

Docker

image

NPM

image
dennypradipta commented 4 months ago
image

Here is the example for using custom user agent