cURL and ActiveMQ - http

I need an example on how to read/write to an ActiveMQ queue over HTTP in C or C++ using cURL (or something else, I'm open to anything at this point).
I have working code in C#, but it doesn't help.
Any help is appreciated,
Thank you.

First I assume:
You are running activemq 5.5.0
You are using the default activemq configuration that enables the web-console
Test it by pointing a browser to http://localhost:8161/admin
By cURL you mean libcurl and a command line example is sufficient
Example:
Create a queue named test, set the body to hello world.
Note: [clientId] this a unique string to identify your subscribe otherwise a new consumer will be created for each request see REST
$ curl -d 'body="Hello World"' "http://localhost:8161/demo/message/test?type=queue&clientId=consumerA"
Pop the message of the queue
$ curl -X delete "http://localhost:8161/demo/message/test?type=queue&clientId=consumerA"
You should see "Hello World"
Finally unsubscribe from the queue
$ curl -d 'action=unsubscribe' "http://localhost:8161/demo/message/test?type=queue&clientId=consumerA"
You should be able to monitor all of the above operations from the admin interface

Until version 5.8, REST API was part of the Web Samples and was mapped
to http://localhost:8161/demo/message url. From 5.8 onwards, the API
is available by default at http://localhost:8161/api/message url
http://activemq.apache.org/rest.html

Related

WSO2 API manager -unable to connect secure websocket (WSS) in configured api publisher

i am using api manager 3.1.0 , i have configured web socket in api publisher , i m trying to access wss and ws . the problem is unable to access wss secure socket-.wss://localhost:8099/Notification/v1?access_token=xxx123 .
but i am able to access ws://localhost:9099/Notification/v1?access_token=xxx123.
can you please guide me, what i have to do configure to access wss,
please refer the screen clip shows unable to verify the first certificate.
enter image description here
enter image description here
Please use the command given in documentation [1] for wss://. I'll post the sample command here. I think you have missed '-n' in the command.
wscat -n -c wss://localhost:8099/echowebsocket/1.0.0 -H "Authorization: Bearer [accesstoken]"
[1] https://apim.docs.wso2.com/en/latest/learn/tutorials/create-and-publish-websocket-api/#step-3-invoke-a-websocket-api

Is there a file upload function in salt stack to upload a jar to JFrog Artifactory?

I am using saltstack state script to create a jar from BitBucket and upload the jar to Artifactory. When uploading to Artifactory I see an authorization error. I am not sure if this is the right approach to achieve the upload to Artifactory.
I tried using CURL to achieve upload. I need to provide -u myUser:myPassword along the CURL command for it to work. I cannot provide the credentials in my salt state scripts. I am looking for a better option to achieve the upload without using login credentials. How to upload artifacts to artifactory using saltstack?
curl -X PUT -T /tmp/Batch.jar http://artifactory/artifactory/Batch.jar
Error:
stdout:
{
\"errors\" : [ {
\"status\" : 401,
\"message\" : \"Unauthorized\"
} ]
}
I've run into this sort of thing a couple of times. The easiest solution is to write a small salt execution module to do this work. This way you can store the artifactory credentials as pillar data and use the normal python requests or salt http helpers to make the web requests.
Looks like salt stack provides a module for artifactory alread: https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.artifactory.html
It may not do exactly what you're looking for, but you could definitely extend it: https://github.com/saltstack/salt/blob/develop/salt/modules/artifactory.py
The saltstack docs for writing execution modules can be here:
https://docs.saltstack.com/en/latest/ref/modules/
According to Artifactory documentation, the REST API supports these forms of authentication:
Basic authentication using your username and password
[Simplest] Basic authentication using your username and API Key.
Using a dedicated header (X-JFrog-Art-Api) with your API Key.
Using an access token instead of a password for basic authentication.
[Recommended] Using an access token as a bearer token in an authorization header
(Authorization: Bearer) with your access token.
You will have to choose one of the above.

Getting started with Sony Audio Control API

Trying to use the new Sony Audio Control API with my STR-DN1080 (firmware M41.R.0377), but having a lot of trouble following the guide on https://developer.sony.com/develop/audio-control-api/. It's certainly pretty looking, but the Tutorials are not very helpful.
So based on that portal, it sounds like I need to discover the receiver's port via SSDP/UPNP. There's not much guidance on how to do this, so I used an Android app "UPNP Browser" and found 3 separate URLs. Within http://str.dn.1080.ip:52323/dmr.xml, I find the base URL:port and available services:
<av:X_ScalarWebAPI_DeviceInfo>
<av:X_ScalarWebAPI_Version>1.0</av:X_ScalarWebAPI_Version>
<av:X_ScalarWebAPI_BaseURL>http://str.dn.1080.ip:10000/sony</av:X_ScalarWebAPI_BaseURL>
<av:X_ScalarWebAPI_ServiceList>
<av:X_ScalarWebAPI_ServiceType>guide</av:X_ScalarWebAPI_ServiceType>
<av:X_ScalarWebAPI_ServiceType>system</av:X_ScalarWebAPI_ServiceType>
<av:X_ScalarWebAPI_ServiceType>audio</av:X_ScalarWebAPI_ServiceType>
<av:X_ScalarWebAPI_ServiceType>avContent</av:X_ScalarWebAPI_ServiceType>
</av:X_ScalarWebAPI_ServiceList>
</av:X_ScalarWebAPI_DeviceInfo>
Then, following the API reference for getSystemInformation (v1.4), I issue a GET to http://str.dn.1080.ip:10000/sony/system/getSystemInformation, but all I get back is {"error":[404,"Not Found"]}
I'm stumped now, and looking for help from Sony Developer Support. What am I missing? Is there something I need to enable on my receiver? Is there a hidden firmware that the Auto Updater won't apply?
Thanks!
For those searching on how to use the Sony API in Windows with curl, and to add onto the accepted answer, you'll need to replace the single quotes with double quotes and then escape the double quotes in the JSON:
curl -i -d "{\"method\": \"getSystemInformation\",\"id\": 1,\"params\":
[],\"version\": \"1.4\"}" http://str.dn.1080.ip:10000/sony/system
For postman, set type to POST, URL to: http://str.dn.1080.ip:10000/sony/system, and specify Body as raw/JSON, and paste the JSON:
{
"method":"getSystemInformation",
"id":1,
"params":[],
"version":"1.4"
}
The Sony Audio Control API is based on POST request.
So you have to use some program that can generate a POST request like curl to send requests
curl -i -d '{"method": "getSystemInformation","id": 1,"params": [],"version": "1.4"}' http://str.dn.1080.ip:10000/sony/system
You can also use programs like postman to send test requests if you want something with a GUI.

How to do nginx request monitoring

I have gone through some tools like nagios, collectd but they din't find best as we need to monitor no_of_req/sec for each virtual host with all response status, with response time also.
I'm Using ELK Stack:
Separate access logs for each server block for better visibility or you can separate charts via URLs.
Then Use ELK stack:
Feed the logs to logstash via filebeat.
Create grok pattern for your log model.
Create charts via kibana and monitor in real time.
For realtime monitoring:
Try netdata, Its amazing. Please note its not a replacement for nagios or zabbix.
After some quick research, I found this: check_nginx_status.pl. I think defining something like:
define command {
command_name check-nginx
command_line $USER1$/check_nginx_status.pl -H $HOSTADDRESS$ -s $ARG1$ -u $ARG2$ $ARG3$ $ARG4$ $ARG5$ $ARG6$
}
is probably just what you're looking for.
The -s flag ($ARG1$) would be the hostname of the virtual host
The -u flag ($ARG2$) would be the specific url (/something/status)
And then the rest of the args would be used if you needed to add any additional flags.
Hope this helps!

Datapower SSH login ignores username

When I ssh to my Datapower node like so: ssh user#192.168.0.1 I receive this response:
ssh user#192.168.0.1
(unknown)
Unauthorized access prohibited.
login:
I then enter in the same username, and am also prompted for a password. I type in my credentials and it works! Why didn't it just read my username the first time?
This is hampering my ability to automate a few basic tasks with shell scripts such as fetching logs for processing.
I agree with #Ken and #Stefan that a XML Management is a more appropriate tool for long term automations, howerver, sometimes we need something quick or temporary (or both) ... and for that a CLI automation is easier and faster to develop.
An easy way to push commands to CLI from a shell script is directing the input and output, like this quick sample:
#!/bin/ksh
DPHOST=datapower.device.company.com
DP_USER_ID="myuser"
DP_PASSWORD="mypasword"
TMPFILE=/tmp/tempfile.dp
OUTFILE=/tmp/outfile.dp
TS=`date +%Y%m%d%H%M%S`
cat << EOF > $TMPFILE
DP_USER_ID
DP_PASSWORD
default
echo show cpu
show cpu
echo show memory
show memory
EOF
ssh -T $DPHOST < $TMPFILE > $OUTFILE.$TS
rm $TMPFILE
Note that if you do not have any application domains defined, you may suppress the "default" after the password
And of course, for security reasons you may request the user and password at run time, rather then have it saved on a plain text file, but that is up to you ... the relevant piece here is that you can redirect the file with the commands to an regular ssh session
If you prefer, something like cat $TMPFILE | ssh -T $DPHOST > $OUTFILE.$TS would also works.
That is because DataPower really isn't a SSH server only using the protocol.
What I do in my scripts is that I do the connection, wait for the response and then send the username as the second command and password as third:
ssh [datapower ip]
(unknown)
Unauthorized access prohibited.
login:
your-username
password:
your-password
'#xi52:
DataPower ignores the passed-in username.
Will using the XML Management interface meet your needs? I probably have some scripts laying around.
Ken

Resources