Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Call "create_event" problem #635

Closed
Punkado opened this issue Sep 5, 2023 · 7 comments
Closed

API Call "create_event" problem #635

Punkado opened this issue Sep 5, 2023 · 7 comments

Comments

@Punkado
Copy link

Punkado commented Sep 5, 2023

Summary

When you try to create a event, via API, you get:

{"code":"api","description":"Malformed parameter type: enabled (string)"}

Looks like the problem is similar to #626

Steps to reproduce the problem

Create user via api, like for example:
curl -d "title=ansible&category=clfdfs745&plugin=pleewru70&target=t2&enabled=1" -X POST http://IP:3012/api/app/create_event/v1 "X-API-Key: 5eb8ccc69ca0arggdfgfddf65d5479a685"

Your Setup

1x master
3x workers

Operating system and version?

Ubuntu 20.04

Node.js version?

v18.17.1

Cronicle software version?

Version 0.9.30

Are you using a multi-server setup, or just a single server?

Multi-server, but single master

Are you using the filesystem as back-end storage, or S3/Couchbase?

No

Can you reproduce the crash consistently?

Yes

Log Excerpts

curl -d "title=ansible&category=clen7h745&plugin=plm6f5u70&target=h2&enabled=1" -X POST http://IP:3012/api/app/create_event/v1 -H "X-API-Key: 5eb8ccc69caertretertq3ade65d5479a685"
{"code":"api","description":"Malformed parameter type: enabled (string)"}

@jhuckaby
Copy link
Owner

jhuckaby commented Sep 5, 2023

Gotta use proper JSON inside your POST data, so you can set data types (e.g. boolean for enabled):

{"title":"ansible","category":"clen7h745","plugin":"plm6f5u70","target":"h2","enabled":true}

So try this:

curl -d '{"title":"ansible","category":"clen7h745","plugin":"plm6f5u70","target":"h2","enabled":true}' -X POST http://ip:3012/api/app/create_event/v1 "X-API-Key: 5eb8ccc69ca0arggdfgfddf65d5479a685"

@jhuckaby
Copy link
Owner

jhuckaby commented Sep 5, 2023

You might also need to set the Content-Type header to application/json in your curl call. I think it's the -H flag.

https://reqbin.com/req/c-woh4qwov/curl-content-type

@Punkado
Copy link
Author

Punkado commented Sep 5, 2023

It works, also giving a json file, with this curl:

curl -d @data.json -X POST http://IP:3012/api/app/create_event/v1 -H "X-API-Key: 5eb8sdfdfdfsdfgrded65d5479a685" --header "Content-Type: application/json"

Any idea to not have the event duplicated every time that i run a ansible role with with this API call?

Thanks a lot!

@jhuckaby
Copy link
Owner

jhuckaby commented Sep 5, 2023

Any idea to not have the event duplicated every time that i run a ansible role with with this API call?

Well, I don't know anything about Ansible, but the API call is named create_event, so it's creating a new event, as per your instructions. If you want to update an event which already exists, use update_event instead, and specify the event's ID.

@Punkado
Copy link
Author

Punkado commented Sep 5, 2023

So imagine that is a bash script, that i will run from time to time. This means that every time that i run, it will create a duplicated event.

I wonder if there is a way to not let it create a event that is exactly like other that already exists or if there is a way to remove all the duplicated events.

@jhuckaby
Copy link
Owner

jhuckaby commented Sep 5, 2023

I dunno, it sounds like you are doing something that Cronicle isn't really designed to handle. Your bash script sounds like it's more of a "bootstrap" -- an "initialization" routine -- that should only be called once when you are setting up your environment.

You may need a more involved script that calls get_event to see if your event already exists, and it does, skip the create_event call.

Another option is, you could have your script call delete_event before it calls create_event, but I am really not sure.

@Punkado
Copy link
Author

Punkado commented Sep 5, 2023

I though about the 2 options, get and delete, is a lot of work, maybe i will try other time.

Thanks a lot for the help.

@Punkado Punkado closed this as completed Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants