Failed to write data to influxDB through Shell script - shell

Config an UDP port 8089 in /etc/influxdb/influxdb.conf:
[[udp]]
enabled = true
bind-address = "0.0.0.0:8089"
database = "testdb"
retention-policy = ""
Started InfluxDB with port 8089
[udp] 2016/06/29 23:17:59 Started listening on UDP: 0.0.0.0:8089
Tried to write metric data in a Shell script:
HOST_OR_IP_OF_INFLUXDB_SERVER=my_ip
PORT=8089
# Refer to line protocol:
# https://docs.influxdata.com/influxdb/v0.9/write_protocols/line/
echo "temperature,machine=unit42,type=assembly internal=32 1434055562000000035" | nc -v -u -w 1 $HOST_OR_IP_OF_INFLUXDB_SERVER $PORT
InfluxDB server showed error message:
[udp] 2016/06/29 23:52:18 Failed to parse points: unable to parse 'X': missing fields
[udp] 2016/06/29 23:52:18 Failed to parse points: unable to parse 'X': missing fields
[udp] 2016/06/29 23:52:18 Failed to parse points: unable to parse 'X': missing fields
[udp] 2016/06/29 23:52:18 Failed to parse points: unable to parse 'X': missing fields
Seems the data sent to server satisfies the line protocol of InfluxDB, can anyone give any clue on the problem? Thanks.

In Bash one can simply skip the nc:
echo -n "temperature,machine=unit42,type=assembly internal=32 1434055562000000035" \
> /dev/udp/$HOST_OR_IP_OF_INFLUXDB_SERVER/$PORT

Related

running browserstack-cypress run --sync ends up with ends up with Client network socket disconnected before secure TLS connection was established

I am trying to use browserstack-cypress with parameter local
Below are my step
run browserstacklocal for linux with command
./BrowserStackLocal --key $BROWSERSTACK_ACCESS_KEY --local-identifier $LOCAL_IDENTIFIER --proxy-host $PROXY_HOST --proxy-port $PROXY_PORT --proxy-pass $PROXY_PASS --proxy-user $PROXY_USER --enable-logging-for-api --force-proxy --force-local --verbose 2 > /dev/null 2>&1 &
- sleep 10
verified above step is successful so next is running browserstack-cypress with below option
browserstack-cypress run --sync --specs "${TEST_SPEC_PATH}" --key $BROWSERSTACK_ACCESS_KEY --cf $TEST_CONFIG_PATH --env TEST_USER_NAME=$UBSTEST_USER_NAME,TEST_USER_PASSWORD=$UBSTEST_USER_PASSWORD,BROWSERSTACK_USER=$BROWSERSTACK_USERNAME,BROWSERSTACK_KEY=$BROWSERSTACK_ACCESS_KEY --verbose 2
I have below in my browserstack.json
{
"auth": {
"username": "username",
"access_key": "password",
},
"connection_settings": {
"local": true,
"local_identifier": "5C0E65F2D95C4E55A8DE465248A44E99"
},
but step above ends up with below error
Got Error in binary downloading request Error: Client network socket disconnected before secure TLS connection was established
at connResetException (internal/errors.js:604:14)
at TLSSocket.onConnectEnd (_tls_wrap.js:1513:19)
at Object.onceWrapper (events.js:417:28)
at TLSSocket.emit (events.js:323:22)
at endReadableNT (_stream_readable.js:1204:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
code: 'ECONNRESET',
path: null,
host: 'bstack-local-prod.s3.amazonaws.com',
port: 443,
localAddress: undefined
I am using node v12.16.1 and npm 6.13.1
Same issue was raised before may be this helps https://github.com/browserstack/browserstack-cypress-cli/issues/126

Shell 'echo' error with ENV VAR been parsed from 'redis-cli INFO' output

I try to monitor Redis health with Zabbix agent and want to parse output for redis-cli INFO command:
$ redis-cli INFO
# Server
redis_version:4.0.9
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:9435c3c2879311f3
...
with shell script and compose JSON file with subset of info values:
{
"redis_version": "4.0.9",
"used_memory": 100,
"used_memory_rss": 200
}
But I have an error when I try to echo parsed values to console. This is my demo script:
#!/bin/bash
FILE_ECHO="/tmp/test_out.txt"
FILE_REDIS="/tmp/test_redis.txt"
echo "redis_version:4.0.9" >${FILE_ECHO}
/usr/bin/redis-cli INFO >${FILE_REDIS}
ECHO_VERSION=$(grep "redis_version" "${FILE_ECHO}")
REDIS_VERSION=$(grep "redis_version" "${FILE_REDIS}")
echo "{\"node\": \"${ECHO_VERSION}\"}"
echo "{\"node\": \"${REDIS_VERSION}\"}"
I expect that output will be:
{"node": "redis_version:4.0.9"}
{"node": "redis_version:4.0.9"}
in both cases, but actually I have:
{"node": "redis_version:4.0.9"}
"}node": "redis_version:4.0.9
This is my test_redis.txt.

aws_launch_configuration: timeout - last error: dial tcp :22: connectex: No connection could be made because the target machine actively refused it

I have the following launch config for an auto-scaling group:
resource "aws_launch_configuration" "ASG-launch-config" {
#name = "ASG-launch-config" # see: https://github.com/hashicorp/terraform/issues/3665
name_prefix = "ASG-launch-config-"
image_id = "ami-a4dc46db" #Ubuntu 16.04 LTS
#image_id = "ami-b70554c8" #Amazon Linux 2
instance_type = "t2.micro"
security_groups = ["${aws_security_group.WEB-DMZ.id}"]
key_name = "MyEC2KeyPair"
#user_data = <<-EOF
# #!/bin/bash
# echo "Hello, World" > index.html
# nohup busybox httpd -f -p "${var.server_port}" &
# EOF
provisioner "file" {
source="script.sh"
destination="/tmp/script.sh"
}
provisioner "remote-exec" {
inline=[
"chmod +x /tmp/script.sh",
"sudo /tmp/script.sh"
]
}
connection {
user="ubuntu"
private_key="${file("MyEC2KeyPair.pem")}"
}
lifecycle {
create_before_destroy = true
}
}
Error: Error applying plan:
1 error(s) occurred:
aws_launch_configuration.ASG-launch-config: timeout - last error: dial tcp :22: connectex: No connection could be made because the target machine actively refused it.
I want to run a bash script to basically install WordPress on the instances created.
the script runs fine in a resource type "aws_instance" "example"
how to troubleshoot this?
Sounds like the instance is denying your traffic. Start up an instance without the provisioning script and see if you can SSH to it using the key you provided. You may want to add verbose logging to the SSH command with -v.

Not able to connect to socket using socat

I am trying to parse rsyslog logs. For this i am sending all my logs to socat which is then sending them to Unix Domain Socket. That socket is created via perl script which is listening on that socket to parse logs.
My bash script to which rsyslog is sending all log is
if [ ! `pidof -x log_parser.pl` ]
then
./log_parser.pl & 1>&1
fi
if [ -S /tmp/sock ]
then
/usr/bin/socat -t0 -T0 - UNIX-CONNECT:/tmp/sock 2>> /var/log/socat.log
fi
/tmp/sock is created using perl script log_parser.pl which is
use IO::Socket::UNIX;
sub socket_create {
$socket_path = '/tmp/sock';
unlink($socket_path);
$listner = IO::Socket::UNIX->new(
Type => SOCK_STREAM,
Local => $socket_path,
Listen => SOMAXCONN,
Blocking => 0,
)
or die("Can't create server socket: $!\n");
$socket = $listner->accept()
or die("Can't accept connection: $!\n");
}
socket_create();
while(1) {
chomp($line=<$socket>);
print "$line\n";
}
There is this error i am getting from socat which is
2015/02/24 11:58:01 socat[4608] E connect(3, AF=1 "/tmp/sock", 11): Connection refused
I am no champion in sockets so i am not able to understand what is this. Please help. Thanks in advance.
The main issue is that when i kill my perl script then bash script is suppose to call it again and start it.
What actually happening is that sript is started but socat is not started instead it give this error and never start.
I can duplicate your error if I don't run your perl program before trying to use socat. Here is what works for me:
1) my_prog.pl:
use strict;
use warnings;
use 5.016;
use Data::Dumper;
use IO::Socket::UNIX;
my $socket_path = '/tmp/sock';
unlink $socket_path;
my $socket = IO::Socket::UNIX->new(
Local => $socket_path,
Type => SOCK_STREAM,
Listen => SOMAXCONN,
) or die "Couldn't create socket: $!";
say "Connected to $socket_path...";
my $CONN = $socket->accept()
or die "Whoops! Failed to open a connection: $!";
{
local $/ = undef; #local -> restore previous value when the enclosing scope, delimited by the braces, is exited.
#Setting $/ to undef puts file reads in 'slurp mode' => whole file is considered one line.
my $file = <$CONN>; #Read one line.
print $file;
}`
2) $ perl my_prog.pl
3) socat -u -v GOPEN:./data.txt UNIX-CONNECT:/tmp/sock
The -u and -v options aren't necessary:
-u Uses unidirectional mode. The first address is only used for
reading, and the second address is only used for writing (exam-
ple).
-v Writes the transferred data not only to their target streams,
but also to stderr. The output format is text with some conver-
sions for readability, and prefixed with "> " or "< " indicating
flow directions.
4) You can also do it like this:
cat data.txt | socat STDIN UNIX-CONNECT:/tmp/sock
Pipe stdout of cat command to socat, then list STDIN as one of socat's files.
Response to comment:
This bash script works for me:
#!/usr/bin/env bash
echo 'bash script'
../pperl_programs/my_prog.pl &
sleep 1s
socat GOPEN:./data.txt UNIX-CONNECT:/tmp/sock
It looks like the perl script doesn't have enough time to setup the socket before socat tries to transfer data.

why xinetd can't run shell service

guys,i have a problem on using xinetd,the error message is 'xinetd[20126]: execv( /home/fulu/download/mysqlchk_status2.sh ) failed: Exec format error (errno = 8)'
the system operation is : CentOS release 6.2;
i installed the xinetd by the command 'sudo yum install xinetd'
i edited the /etc/services, add my port 6033 for my service named 'mysqlchk'
the service 'mysqlchk' in /etc/xinetd.d/mysqlchk is
service mysqlchk
{
disable = no
flags = REUSE
socket_type = stream
port = 6033
wait = no
user = fulu
server = /home/fulu/download/mysqlchk_status2.sh
log_on_failure += USERID
}
the shell file /home/fulu/download/mysqlchk_status2.sh content is
echo 'test'
6.i can run the command /home/fulu/download/mysqlchk_status2.sh straightly and get the result 'test'
when i telnet 127.0.0.1 6033,i get the output
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Connection closed by foreign host.
then i tail the log file /var/log/messages,it shows
Apr 22 22:01:47 AY1304111122016 xinetd[20001]: START: mysqlchk pid=20126 from=127.0.0.1
Apr 22 22:01:47 AY1304111122016 xinetd[20126]: execv( /home/fulu/download/mysqlchk_status2.sh ) failed: Exec format error (errno = 8)
Apr 22 22:01:47 AY1304111122016 xinetd[20001]: EXIT: mysqlchk status=0 pid=20126 duration=0(sec)
i don't know why,can anybody help me ?
I'm sorry, after questioning it i suddenly found the answer. If you want the shell to be run in other program you need add '#!/bin/echo' at the first line of the shell file (of course the echo can be changed)

Resources