how work with shinken livestatus API - monitoring

Good day. I first work with Shinken and similar products in general.So do not judge strictly.
The question is how to get the data through Shinken Livestatus API.
Shinken is installed and running. Livestatus is configured and running on the localhost:50000. Ping is coming.
But I can not understand how to ask something, get some data. The documentation did not shed much light on my question. And whether it is possible through this API to receive metrics which sends CollecD to mod-collectd

After experimenting and studying the source code, I came to this conclusion. In the livestatus module, you can open a port or unixsocket, this is understandable. But here you can refer to it from the commands found in the source code mapping.py in the dictionary livestatus_attribute_map.
The main thing after the request is to put two line breaks !!!
Example thru HTTP:
curl -i -X POST http://host:50000/query -H "Content-Type: text/xml" --data-binary "#/path_to_query/query"
query - this is file, with command.
Example: cat query
----------------------
GET hosts
----------------------
The main thing is not to forget about the transfer line!

Related

Event Bridge schedulers - Call my API gateway endpoint

I'm trying to use event bridge's new scheduler functionality:
I don't see the option "Call endpoint...", I did further reading and apparently is possible by sending a JSON but the format of that JSON is a big mystery and I can't find an example.
Is it possible to provide a working example of that, all that I tried is just not working.
EDIT:
This is an AWS cli example for something else:
aws scheduler create-schedule --schedule-expression "at(2022-11-20T13:00:00)" --name schedule-name \
--target '{"RoleArn": "role-arn", "Arn": "QUEUE_ARN", "Input": "TEST_PAYLOAD" }' \
--schedule-expression-timezone "America/Los_Angeles"
--flexible-time-window '{ "Mode": "OFF"}'
The --target should be changed to call my API gateway endpoint but I can't figure out what are the required fields.
EDIT2:
Was suggested that (this question) may provide a solution, but so far the accepted solution raises another question:
It appears you are right that the brand-new EventBridge Scheduler
console interface does not yet (?) support API Destinations.
I would like to do it in schedulers not rules, the way I see it schedulers is more adequate to what I'm trying to do, and I already have a solution using rules

http POST method for web server

I'm looking at HTTP POST method to create a web page.
I'm a tad unfamiliar with it, and was looking for some explanation on how this works.
I'm simply wanting to use their seemingly simplistic page for my own server needs.
My question is this, how does this curl link really work?
curl --data-binary #audio2.flac --header 'Content-type: audio/x-flac; rate=16000' 'https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&pfilter=0&maxresults=1&lang="en-US"'
So I got it to work by using curl, by sending a flac file as you can see, and it responds with
this JSon stuff
{"status":0,"id":"3b7853241a0dded048f84744cc1ab896-1","hypotheses":[{"utterance":"ice cream","confidence":0.88215643}]}
Please correct me if I'm wrong:
So I believe this is a post method as it has the ? mark with it to send the name value pair.
I have no idea how they got the link https://www.google.com/speech-api/v1/recognize
to only accept POST requests without having a script name like this at the end
https://www.google.com/speech-api/v1/recognize/scriptName.pl
How do I write something to accept a post request at that given page without a .pl or .py extension? How can I put it in a certain directory on the server.
In addition for my purposes can I also send a file back to them once I process / zip?
Any ideas on how to do that?
Thanks so much for your time and generous help!
It seems that if you use --data/--data-binary/--form that the request is POSTed.
I first totally misunderstood your question and though you wanted to know how to use the interface, but you got that working.
The serverside can be achieved by multiple means, totally depending on the infrastructure and software used.
With the Webserver apache for example, you could use Rewrite or something in a HtAccess file to obfuscate/change the requested file. So looking at the extension (or the absence of it) is not helpful.
Please also see various options mentioned here
Running PHP without extension without using mod_rewrite?
or
ForceType/htaccess file extension question - extensionless files?
to see how you could achieve the same.
Only accepting POST data is then again dependant on the programming/scripting technique you employ at your server side, PHP e.g. distinguishes between multiple superglobals like $_GET and $_POST.

How do I execute this command (curl) in rails? That is, what library contains a tool that allows me to pass an API key this way?

Here's the command I need to execute: (using the example API key)
curl -v -u 1971800d4d82861d8f2c1651fea4d212:api_token \
-X GET https://www.toggl.com/api/v8/workspaces/777/tasks
I am writing a dashing/sinatra based dashboard that shows a summary of the information from our Toggl account. My question is, how to I open this url in sinatra using something like
open('http://...) do |f|
A successful curl returns an array (json) that I can parse for the info I need.
I'm not entirely sure how to tackle this. I have some ideas but they aren't well formed enough to properly comment on them. I though I'd bounce this off of you all for inspiration and information.
I'm all ears.
Check out HTTParty. The example in the README shows basically exactly what you're looking to do using auth headers:
https://github.com/jnunemaker/httparty

Rails: How to process a file that was sent with curl

I'm trying to create a restful api capable of receiving a file.
http://leejava.wordpress.com/2009/07/30/upload-file-from-rest-in-ruy-on-rail-with-json-format/
talks of how to accomplish this simply.
Not being very used to rails or curl, I don't know how to formulate my curl call.
Could anyone help me. Explain how to use curl to send a file, and how to use rails to accept and store the file.
Note.. the file is a 10 meg zip file. For testing I called it.
C:\test.zip..
I've looked at tutorials, but they all seem to be web page based. They also all degrade to resizing pictures.. Like uploading and presenting images are the same topic.
You need to know a bit about how your server-side is expecting the data. If it is a http POST with multipart/form-data (which I think it is), then this will probably help:
curl -F "fileParam=#c:\test.zip" -F "param1=xxx" -F "param2=yyyy" http://my.server/post-service
This will use curl to post form-data (including a file) to the given url with the given parameters. You need to know the parameter names for the file and the other optional parameters, and you have to obviously get the URL correct to reach your service.
Hope that helps.

How do I send in a REST request (to use an API)?

I'm writing a small web app for myself in Rails and I want it to use Last.fm's API. I'm incredibly new to web development in general, so I'm not sure where to even begin.
http://www.last.fm/api/rest
I'm not asking for a step-by-step tutorial or anything like that, but a nudge in the right direction would be awesome. Or even just a little example code.
Installing HTTParty will get you started, you might also want to make some calls to the API from the command line using cURL just to understand how it works. Just type cURL and the restful URL on the commandline:
prompt> curl http://www.whatever.com/resource for a get
prompt> curl -d '{ "arg" : "value" }' http://www.whatever.com/ for posts etc.
Often understanding what comes back in each of the calls will help you structure your app. Have fun.
Dupe of this 748614
Simply speaking - use the HTTParty gem, it does literally everything for you.

Resources