I'm trying to set Artillery config to be able to send nested JSON body. This is how my configuration looks like:
config:
target: <URL>
phases:
- duration: 10
arrivalRate: 20
processor: "./input-parser.js"
scenarios:
- flow:
- function: "parseJsonFile"
- post:
url: /workflow-instance
headers:
Content-Type: "application/json"
json:
name: "{{ name }}"
namespace: "{{ namespace }}"
template_name: "{{ template_name }}"
attributes: "{{ attributes }}"
- get:
url: "/workflow-instance/status?name={{ template_name }}&namespace={{ namespace }}"
I have a problem with "attributes" because the content of attributes is:
{ pod_name: 'POD_NAME', port: 'PORT_NUMBER' }
So basically, this will not work:
attributes: "{ pod_name: 'POD_NAME', port: 'PORT_NUMBER' }"
as well as this:
attributes:
pod_name: 'POD_NAME'
port: 'PORT_NUMBER'
I didn't found good examples for this particular case in Artillery docs.
The following workaround worked for me Embedding JSON Data into YAML file
Then you'd have to change your attributes for:
attributes: '{ pod_name: "POD_NAME", port: "PORT_NUMBER" }'
I'm using:
Artillery: 1.7.9
Artillery Pro: not installed (https://artillery.io/pro)
Node.js: v14.6.0
OS: darwin/x64
For future readers looking for hardcoding nested JSON, this worked for me:
...
scenarios:
-
flow:
-
post:
url: "/"
json:
text: {"filter": {"enabled": true}}
Related
We use Prometheus alert manager for alerts, we have configured two receivers as attached below, Slack and Opsgenie.
The issue is that we are getting alerts in slack only but we are not receiving alerts in Opsgenie, we use the API keys and it's a working key, we tested it.
Not able to figure why we are not receiving alerts in Opsgenie too.
global:
resolve_timeout: 5m
route:
group_by: ['alertname']
group_wait: 10s
group_interval: 10s
repeat_interval: 30m
receiver: 'prod_alert_slack'
routes:
# Send severity=page alerts to the pager.
- match:
severity: critical|warning|page
receiver: team-pager
receivers:
- name: team-pager
opsgenie_configs:
- responders:
- name: 'Oncall'
type: 'team'
api_key: XXXXXXXXXXXXXXXXX
- name: 'prod_alert_slack'
slack_configs:
- api_url: https://hooks.slack.com/services/XXXXXXXX/XXXXXXXXXXXX
channel: '#prodslack'
send_resolved: true
username: '{{ template "slack.default.username" . }}'
color: '{{ if eq .Status "firing" }}danger{{ else }}good{{ end }}'
title: '{{ template "slack.default.title" . }}'
title_link: '{{ template "slack.default.titlelink" . }}'
pretext: '{{ .CommonAnnotations.summary }}'
text: |-
{{ range .Alerts }}
*Alert:* {{ .Annotations.summary }} - `{{ .Labels.severity }}`
*Description:* {{ .Annotations.description }}
*Message:* {{ .Annotations.message }}
*Details:*
{{ range .Labels.SortedPairs }} • *{{ .Name }}:* `{{ .Value }}`
{{ end }}
{{ end }}
fallback: '{{ template "slack.default.fallback" . }}'
icon_emoji: '{{ template "slack.default.iconemoji" . }}'
icon_url: '{{ template "slack.default.iconurl" . }}'
#text: "summary: {{ .CommonAnnotations.summary }}\ndescription: {{ .CommonAnnotations.description }}"
inhibit_rules:
- source_match:
severity: 'critical'
target_match:
severity: 'warning'
equal: ['alertname', 'dev', 'instance']```
I'm making API documentation on swagger and using YAML.
This is my YAML code
swagger: "2.0"
info:
title: Sign_up Api
description: This Will alow user to Signup.
version: 1.0.0
host: e9ea53234b75.ngrok.io
basePath: /customer_app/api/v1
schemes:
- https
paths:
/sign_up:
post:
summary: Return User Credentials After signup.
parameters:
- in: body
name: body
required: true
# type: string
schema:
type: object
properties:
email:
type: string
example: test123#gmail.com
password:
# type: string
example: test123
password_confirmation:
# type: integer
example: test123
name:
type: string
example: testabc
description: User can be signup by providing the listed params & it will return a authentication token and other user params.
produces:
- application/json
responses:
200:
description: User credentials.
properties:
id:
type: string
example: 70020ed1-50fe-4c7e-afed
password:
# type: string
example: pasw123
password_confirmation:
# type: string
example: pasw123
name:
type: string
example: testabc
422:
description: The specified email is invalid (e.g. not following the syntax) or paswwords are not same or missing params.
default:
description: Unexpected error
and im getting my params in rails by
params.require(:user).permit(:email, :password , :password_confirmation, :uuid, :name)
in this way I'm sending my params from the postman
and getting this response
<ActionController::Parameters {"user"=><ActionController::Parameters {"email"=>"moon123#gmail.com", "password"=>"moon123", "password_confirmation"=>"moon123", "name"=>"moon123"} permitted: false>, "format"=>:json, "controller"=>"customer_app/api/v1/registrations", "action"=>"create"} permitted: false>
but by using user[email] in YAML got this in a wrong way
<ActionController::Parameters {"user[email]"=>"test123#gmail.com", "user[password]"=>"test123", "user[password_confirmation]"=>"test123", "user[name]"=>"testabc", "format"=>:json, "controller"=>"customer_app/api/v1/registrations", "action"=>"create", "registration"=>{"user[email]"=>"test123#gmail.com", "user[password]"=>"test123", "user[password_confirmation]"=>"test123", "user[name]"=>"testabc"}} permitted: false>
I don't know how to edit my YAML to get the response as I got from Postman.
Postman's "form-data" bodies are for requests with Content-Type: multipart/form-data. In OpenAPI 2.0, such requests need to have consumes: [multipart/form-data], and the body fields are defined as in: formData parameters.
swagger: '2.0'
...
paths:
/sign_up:
post:
summary: Return User Credentials After signup.
consumes:
- multipart/form-data
parameters:
- in: formData
name: user[email]
type: string
format: email
x-example: test123#gmail.com
- in: formData
name: user[password]
type: string
format: password
x-example: test123
- in: formData
name: user[password_confirmation]
type: string
format: password
x-example: test123
- in: formData
name: user[name]
type: string
x-example: testabc
I want to set Request Validator of API Gateway by serverless. I tried two different settings for the Request Validator. But, both methods have failed. I have summarized what I did, so please let me know if there is something wrong.
I write the API specification in swagger(OAS3.0). Therefore I tried to realize the setting of Request Validator using OAS extension. After I did sls deploy using below swagger.yaml and serverless.yml, None of the validate patterns described in x-amazon-apigateway-request-validators were added to the Request Validator options.
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-request-validator.html
swagger.yaml is below:
openapi: 3.0.0
info:
description: xxx
version: '0.1'
title: xxx API
x-amazon-apigateway-request-validators:
body-only:
validateRequestBody: true,
validateRequestParameters: false
except-body:
validateRequestBody: false,
validateRequestParameters: true
all:
validateRequestBody: true,
validateRequestParameters: true
tags:
- name: auth
description: xxx
paths:
/login:
post:
tags:
- auth
summary: xxx
description: ''
x-amazon-apigateway-request-validator: all
responses:
'200':
description: success
content:
application/json:
schema:
$ref: '#/components/schemas/AuthResponse'
'400':
description: fail
content:
application/json
'401':
description: fail
content:
application/json
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/AuthRequest'
required: true
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
uri: "arn:aws:apigateway:ap-northeast-1:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-northeast-1:xxxxxxxxxxxx:function:xxx-api-dev-login/invocations"
passthroughBehavior: "when_no_match"
httpMethod: "POST"
contentHandling: "CONVERT_TO_TEXT"
type: "aws_proxy"
My serverless.yml is below:
resources:
Resources:
RestApi :
Type : AWS::ApiGateway::RestApi
Properties :
Body : ${file(./swagger.yaml)}
LoginApiToInvokeLambda:
Type: AWS::Lambda::Permission
DependsOn: LoginLambdaFunction
Properties:
FunctionName: xxx-ext-api-dev-login
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
I tried to realize the setting of Request Validator using AWS::ApiGateway::RequestValidator. After I did sls deploy using above swagger.yaml and below serverless.yml, the all described in RequestValidatorAll in severless.yml were added to the Request Validator options. But the default value of Request Validator was still NONE.
resources:
Resources:
RestApi :
Type : AWS::ApiGateway::RestApi
Properties :
Body : ${file(./swagger.yaml)}
LoginApiToInvokeLambda:
Type: AWS::Lambda::Permission
DependsOn: LoginLambdaFunction
Properties:
FunctionName: xxx-ext-api-dev-login
Action: lambda:InvokeFunction
Principal: apigateway.amazonaws.com
RequestValidatorAll:
Type: AWS::ApiGateway::RequestValidator
Properties:
Name: all
RestApiId:
Ref: RestApi
ValidateRequestBody: true
ValidateRequestParameters: true
You need to remove the commas in your YAML.
i.e
x-amazon-apigateway-request-validators:
body-only:
validateRequestBody: true,
validateRequestParameters: false
except-body:
validateRequestBody: false,
validateRequestParameters: true
all:
validateRequestBody: true,
validateRequestParameters: true
should be
x-amazon-apigateway-request-validators:
body-only:
validateRequestBody: true
validateRequestParameters: false
except-body:
validateRequestBody: false
validateRequestParameters: true
all:
validateRequestBody: true
validateRequestParameters: true
Once you do this the YAML will be valid and it should work.
Hi i am trying to send the Default values through body parameters but its Not taking while Submitting. can anybody please help me on this issue. Here is my code and i am trying to send the default name parameter through body
swagger: '2.0'
info:
version: 1.0.0
title: PetStore on Heroku
description: |
**This example has a working backend hosted in Heroku**
You can try all HTTP operation described in this Swagger spec.
Find source code of this API [here](https://github.com/mohsen1/petstore-api)
host: petstore-api.herokuapp.com
basePath: /pet
schemes:
- http
- https
consumes:
- application/json
- text/xml
produces:
- application/json
- text/html
paths:
/:
get:
parameters:
- name: limit
in: query
description: number of pets to return
type: integer
default: 0
responses:
200:
description: List all pets
schema:
title: Pets
type: array
items:
$ref: '#/definitions/Pet'
post:
parameters:
- name: pet
in: body
description: The pet JSON you want to post
schema:
$ref: '#/definitions/Pet'
required: true
responses:
200:
description: Make a new pet
put:
parameters:
- name: pet
in: body
description: The pet JSON you want to post
schema:
$ref: '#/definitions/Pet'
required: true
responses:
200:
description: Updates the pet
/{petId}:
get:
parameters:
- name: petId
in: path
type: string
description: ID of the pet
required: true
responses:
200:
description: Sends the pet with pet Id
definitions:
Pet:
type: object
properties:
name:
type: string
default : "xxxxxxx"
birthday:
type: integer
format: int32
The default value should be handled in the server side as the server should not always assume the client sends HTTP requests that are 100% conforming to the spec.
I think this can help you, if you are trying to send default data with your schema:
definitions:
Pet:
type: object
default:
name: xxxx
birthday: xxxx
properties:
name:
type: string
birthday:
type: integer
format: int32
I'm using Ruby with the Mechanize GEM to log in to TDAmeritrade's website.
I try to execute: page = agent.get('https://invest.ameritrade.com/grid/p/login') and it returns page.forms as follows:
2.0.0-p0 :049 > page.forms
=> [#<Mechanize::Form
{name nil}
{method "POST"}
{action "https://invest.ameritrade.com/grid/p/login"}
{fields
[hidden:0x5b6684a type: hidden name: mAction value: submit]
[hidden:0x5b665a2 type: hidden name: fp_browser value: ]
[hidden:0x5b66386 type: hidden name: fp_screen value: ]
[hidden:0x5b661e2 type: hidden name: fp_software value: ]
[hidden:0x5b6f36e type: hidden name: fp_timezone value: ]
[hidden:0x5b6ffb2 type: hidden name: fp_language value: ]
[hidden:0x5b6fe5e type: hidden name: fp_java value: ]
[hidden:0x5b6fcc4 type: hidden name: fp_cookie value: ]
[hidden:0x5b6fbfc type: hidden name: flashVersion value: ]
[selectlist:0x5b6f756 type: name: ldl value: main:home]}
{radiobuttons}
{checkboxes}
{file_uploads}
{buttons [button:0x5b6eafe type: submit name: value: ]}>
]
As you can see, neither the username nor password fields are shown even though they can be seen on the website in a browser. How do I log in to TDAmeritrade with my Ruby script using the Mechanize GEM (http://mechanize.rubyforge.org/)?
Thanks in advance.
For sites that login via a POST request, you can manually capture the XHR in something like Firebug and replicate it in your code.
For example, the site you have listed has a bunch of hidden fields that get added on submission of a username and password. Luckily, you can pass a hash to a POST request call on your Mechanize::Agent.
#agent.post("https://invest.ameritrade.com/grid/p/login",
{"tbPassword" => yourPass, "tbUsername" => yourUsername})
Of course you'll need to add the additional fields as well.
example POST XHR from Firebug for your example site
flashVersion 11.9.900
fp_browser mozilla/5.0 (macintosh; intel mac os x 10.8; rv:24.0) gecko/20100101 firefox/24.0|5.0 (Macintosh)|MacIntel
fp_cookie 1
fp_java 1
fp_language lang=en-US|syslang=|userlang=
fp_screen 24|2560|1440|1440
fp_software
fp_timezone -4
ldl main:home
mAction submit
tbPassword yourPassword
tbUsername yourUsername
You might run into problems with mechanize on different sites that implement javascript. You might want to try using the watir-webdriver or if it's a site that has a lot of javascript use you might be better off using phantomjs.