Unsupported command format with token - '""' Aerospike - aerospike

I am trying to insert a record in aerospike as following :
insert into NameSpace.SetName(PK,id,value,formId) values("1","23","hello","");
And I am getting following error:
Unsupported command format with token - '""'
Make sure string values are enclosed in quotes.
Type " aql --help " from console or simply "help" from within the aql-
prompt.
Any help is appreciated.

Seems to work for me:
$ aql
Seed: 127.0.0.1
User: None
Aerospike Query Client
Version 3.15.3.14
C Client Version 4.3.12
Copyright 2012-2017 Aerospike. All rights reserved.
aql> insert into test.stackoverflow (PK,id,value,formId) values("1","23","hello","");
OK, 1 record affected.
aql> select * from test.stackoverflow where PK="1"
+------+---------+--------+
| id | value | formId |
+------+---------+--------+
| "23" | "hello" | "" |
+------+---------+--------+
1 row in set (0.011 secs)
OK
The server version is
$ asd --version
Aerospike Community Edition build 4.3.0.2
Alternatively, use one of the language clients. You shouldn't be trying to build an application over AQL, it's just a tool for admin (with light-weight data browsing).
Install
$ sudo yum install python-devel
$ sudo yum install openssl-devel
$ pip install aerospike
$ python
Run
>>> import aerospike
>>> config = {'hosts': [('127.0.0.1', 3000)]}
>>> client = aerospike.client(config).connect()
>>> key = ('test', 'stackoverflow', '1')
>>> client.put(key, {'id': '23', 'value': 'hello', 'formId': ''})
0L
>>> import pprint
>>> pprint.pprint(client.get(key))
(('test',
'stackoverflow',
None,
bytearray(b'CHu\xf09%a\xf0\x8d\x86\x14\x0f\xea\x93\xeb\xf6\x7f\x16\x87\xd0')),
{'gen': 1, 'ttl': 431818},
{'formId': '', 'id': '23', 'value': 'hello'})

Related

Ansible - use registered variable that contains semicolon to install exact apt package

I want to create a role to install latest "xx.yy" or "xx" version of a package on multiple Debian distributions.
Starting with a more generic version I use apt-cache madison, filter the results to get latest version available for that machine an register the value. I am then trying to use this value (that contains special characters) to install exact package version.
For example to install docker I use the following:
vars/main.yaml
docker_engine:
version: 20.10
tasks/main.yaml
- name: Get latest docker version
shell: "apt-cache madison docker-ce | grep {{ docker_engine.version }} | head -1 | awk '{ print $3 }'"
register: docker_exact_version
- name: Display docker_exact_version value
debug:
var: docker_exact_version
tags: debug_info
- name: Install Docker Engine
apt:
update_cache: yes
name: docker-ce= {{ docker_exact_version }}
This fails with
Output:
ok: [...] => {
"docker_exact_version": {
...
"cmd": "apt-cache madison docker-ce | grep 20.1 | head -1 | awk '{ print $3 }'",
"stdout": "5:20.10.18~3-0~debian-bullseye",
...
}
}
...
fatal: [...]: FAILED! =>
File \"/usr/lib/python3.9/sre_parse.py\", line 598, in _parse\r\n raise source.error(msg, len(this) + 1 + len(that))\r\nre.error: bad character range 3-0 at position 35\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
If I manually introduce the version and escape the semicolon it's working fine.
- name: Install Docker Engine
apt:
update_cache: yes
name: docker-ce=5\:20.10.18~3-0~debian-bullseye
How can I escape semicolon when using the registered variable?
Thanks a lot

Connect Raspberry Pi to SQL Server using pyodbc error: [08001] [FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)

I'm trying to connect a raspberry pi 3 to a local SQL Server.
I did this:
sudo apt-get install unixodbc
sudo apt-get install unixodbc-dev
sudo apt-get install freetds-dev
sudo apt-get install tdsodbc
sudo apt-get install freetds-bin
sudo pip3 install pyodbc
sudo apt-get install python-pyodbc
sudo nano /etc/freetds/freetds.conf
Added this block
[sqlserver]
host = 192.168.0.109 # Sql Server's IP addr
port = 1433 # default
tds version = 7.0 #
instance = Database1 # Database name
now in /etc/odbcinst.ini
[FreeTDS]
Description = FreeTDS unixODBC Driver
Driver = /usr/lib/arm-linux-gnueabihf/odbc/libtdsodbc.so
Setup = /usr/lib/arm-linux-gnueabihf/odbc/libtdsodbc.so
UsageCount = 1
and in /etc/odbc.ini file as follows:
[NAME1]
Driver = /usr/lib/arm-linux-gnueabihf/odbc/libtdsodbc.so
Description = MSSQL Server
Trace = No
Server = ServerName1
Database = Database 1
Port = 1433
TDS_Version = 7.4
when I run
tsql -S sqlserver -U username
I can connect t the database and run queries, but When I try
tsql isql NAME1 user 'password'
I get
[ISQL]ERROR: Could not SQLConnect
I got a python script with
class SQL:
cnxn = None
cursor= None
def __init__(self):
try:
self.cnxn = pyodbc.connect('DRIVER={FreeTDS}; SERVER= ws2016_01; DATABASE=databasename; UID=user; PWD=password;TDS_Version=7.2;')
self.cnxn.setdecoding(pyodbc.SQL_CHAR, encoding='utf-8')
self.cnxn.setdecoding(pyodbc.SQL_WCHAR, encoding='utf-8')
self.cnxn.setencoding(encoding='utf-8')
And I keep getting the error
[08001] [FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)
Thanks for reading, any help would be deeply appreciated!

Unable to get data from PostgreSQL using mod_lua

This is my setup:
OS: Linux Ubuntu 14.04 64bit
DB: Postgres 9.4 (installed from official Postgres repo)
Apache: 2.4.7 with mod_lua manually compiled from source in Apache 2.4.20 and installed
Database init script is as follows:
CREATE TABLE users (
id SERIAL PRIMARY KEY,
client VARCHAR(20) NOT NULL UNIQUE,
secret VARCHAR(20) NOT NULL
);
INSERT INTO users(client, secret) VALUES('john' , 'john' );
INSERT INTO users(client, secret) VALUES('apple', 'orange');
INSERT INTO users(client, secret) VALUES('kiwi' , 'pear' );
INSERT INTO users(client, secret) VALUES('peach', 'berry' );
Apache has enabled mod_dbd that is configured as follows:
<IfModule dbd_module>
DBDriver pgsql
DBDPersist on
DBDMax 20
DBDParams "host='localhost' port='5432' dbname='demousers' user='postgres' password='postgres'"
DBDPrepareSQL 'SELECT u.secret FROM users u WHERE u.client=%s' client_secret
</IfModule>
There is also mod_lua which is configured like this:
<IfModule lua_module>
LuaRoot /vagrant/luatest
LuaScope thread
LuaCodeCache stat
LuaHookAccessChecker /vagrant/luatest/cookie_handler.lua handler early
LuaHookAccessChecker /vagrant/luatest/handler.lua handler late
</IfModule>
This is the sample code that I'm trying to execute in handler.lua that fails:
require "string"
require "apache2"
local inspect = require "inspect"
function handler(r)
local db, err = r:dbacquire()
if not db then
r:debug("[500] DB Error: " .. err)
return 500
end
r:debug("Acquired database")
local statement, errmsg = db:prepared(r, "client_secret")
if not statement then
r:debug("[500] DB Error: " .. errmsg)
db:close()
return 500
end
r:info("Acquired prepared statement")
local secret
local result, emsg = statement:select("john")
if not emsg then
r:info("Fetch rows")
local rows = result(0, true)
r:debug("Rows " .. inspect(rows))
for k, row in pairs(rows) do
r:info("Pass " .. k .. inspect(row))
if row[1] then
secret = string.format("%s", row[1])
end
end
else
r:debug( "Error : " .. emsg)
end
db:close()
return 403
end
Looking at the postgres sql log I see that the query was correctly executed and parameter passed. The issue is that I get the record that has no values just nil placeholders in lua table - rows is like this
{ {} }
So, is this a bug or my mistake?
Unfortunately it is a bug. For details see:
https://bz.apache.org/bugzilla/show_bug.cgi?id=56379
This is the solution that fixes the problem
# Install Apache 2.4.10 from backports repo that has working mod_lua
sudo apt-get install -y -t trusty-backports apache2 apache2-dev apache2-utils
sudo apt-get install -y libaprutil1-dbd-pgsql
# Install lua dependencies
sudo apt-get build-dep -y lua5.1
sudo apt-get install -y lua5.1
sudo apt-get install -y liblua5.1-0-dev
# Get the source code
APACHEVER='2.4.10'
cd /tmp/
apt-get source -y apache2="$APACHEVER"
mv "apache2-$APACHEVER/modules/lua/lua_dbd.c" "apache2-$APACHEVER/modules/lua/lua_dbd.c_original"
# Applying the patch for https://bz.apache.org/bugzilla/show_bug.cgi?id=56379
# without it dbd + lua + postgres do not work - you need to previously prepare the patched c file
cp -u /vagrant/lua_dbd.c "apache2-$APACHEVER/modules/lua/"
cd "apache2-$APACHEVER/modules/lua"
# Build and install patched lua module
sudo apxs -I/usr/include/lua5.1 -cia mod_lua.c lua_*.c -lm -llua5.1
sudo service apache2 restart

How to configure puppet so that it installs yum repos with debug mode?

When i run puppet apply, it tries to install packages using the following command:
/usr/bin/yum -d 0 -e 0 -y install couchdb-1.2.0-7.el6
How can i configure so that it runs it as following instead:
/usr/bin/yum -y install couchdb-1.2.0-7.el6
That is, without removing the debug logs?
You could create a module with an exec resource in it.
> exec {
>
> "couchdb":
> command => "/usr/bin/yum -y -d 0 install couchdb-1.2.0-7.el6",
> path => "/usr/local/bin/:/bin/",
>
> }
as a test I did an update to my wget. Before running the module wget was at 1.11.4-2.el5. In my repository I had 1.11.4-3.el5_8.1.
Here are the results of my 'yum update list wget.x86_64':
Installed Packages
wget.x86_64 1.11.4-2.el5 installed
Available Packages
wget.x86_64 1.11.4-3.el5_8.1 update
this is my puppet output after applying the class (with a debug option to show you the ouput):
debug: Executing '/usr/bin/yum -y -d 0 update wget.x86_64' notice:
/Stage[main]/Yum-update-test/Exec[wget]/returns: executed successfully
And this is the output of the 'yum update list wget.x86_64' after the class/module was applied:
Installed Packages
wget.x86_64 1.11.4-3.el5_8.1 installed
While waiting for a real fix thru this ticket:
https://tickets.puppetlabs.com/browse/PUP-3453
Your only solution is to modify directly the yum package provider:
/usr/lib/ruby/site_ruby/1.8/puppet/provider/package/yum.rb
def install
wanted = #resource[:name]
# If not allowing virtual packages, do a query to ensure a real package exists
unless #resource.allow_virtual?
yum *['-d', '0', '-e', '0', '-y', install_options, :list, wanted].compact
end
Change the '-d' value to 10 and you'll be done
If you provide yum the -d or -e options multiple times, it will use the most recent values. So, you can also use install_options on your package resources. For example:
package { 'wget':
install_options => ['-d' , '10' , '-e' , '1' , '-v'],
}
your puppet log will then include something like:
2017-10-19 14:02:48 +0000 Puppet (debug): Executing: '/usr/bin/yum -d 0 -e 0 -y -d 10 -e 1 -v install wget'
... and all of the debug output.

RabbitMQ: Verify version of rabbitmq

How can I verify which version of rabbitmq is running on a server?
Is there a command to verify that rabbitmq is running?
sudo rabbitmqctl status
and look for line that looks like that:
{rabbit,"RabbitMQ","2.6.1"},
You can simply execute from the command line:
sudo rabbitmqctl status | grep rabbit
If rabbitimq can not start I found the only way to determine version is via installer system.
Eample Debian/Ubuntu:
dpkg -s rabbitmq-server | grep Version
If you have no access to rabbitmqctl or rabbitmq-server is not running, on linux do :
ls /usr/lib/rabbitmq/lib/
I got :
rabbitmq_server-3.5.6
As Marek said on a local server, or, on a remote server (using amqplib):
from amqplib import client_0_8 as amqp
import sys
conn = amqp.Connection(host=sys.argv[1], userid="guest", password="guest", virtual_host="/", insist=False)
for k, v in conn.server_properties.items():
print k, v
Save as checkVersion.py and run with python checkVersion.py dev.rabbitmq.com:
% python checkVersion.py dev.rabbitmq.com
information Licensed under the MPL. See http://www.rabbitmq.com/
product RabbitMQ
copyright Copyright (C) 2007-2011 VMware, Inc.
capabilities {}
platform Erlang/OTP
version 2.6.0
On debian systems, you can just run:
dpkg-query --showformat='${Version}' --show rabbitmq-server
To get RabbitMQ version using the .NET/C# RabbitMQ Client Library:
using (var connection = connectionFactory.CreateConnection())
{
if (connection.ServerProperties.ContainsKey("version"))
Console.WriteLine("Version={0}",
Encoding.UTF8.GetString((byte[])connection.ServerProperties["version"]));
}
Output:
Version=3.6.3
In the likely event you're using the "management" (web) plug-in, the RabbitMQ version appears in the upper-right corner of every web page, along with the version of the Erlang run-time.
I use following command to trim output down to version,
rabbitmqctl status | grep "{rabbit,\"RabbitMQ\""
Output:
{rabbit,"RabbitMQ","3.7.3"},
Since I was looking to do this in C# on a Windows machine and all the current answers are for *nix, I'll post the code that I ended up using:
public string GetRabbitMqVersion()
{
string prefix = "rabbitmq_server-";
var dirs = System.IO.Directory.EnumerateDirectories(#"C:\Program Files (x86)\RabbitMQ Server", string.Format("{0}*",prefix));
foreach (var dir in dirs)
{
//Just grab the text after 'rabbitmq_server-' and return the first item found
var i = dir.LastIndexOf(prefix);
return dir.Substring(i+16);
}
return "Unknown";
}
On Centos you can use yum list rabbitmq-server.
Login to management ui and in top right you can find the version. Also use the following command to find the version
# sudo bash
# rabbitmqctl status | grep rabbit