eth0 interface getting listed 3 times - unix

I am on WSL 2 and using the nix crate in Rust and listing the network interfaces as shown below:
let ifaces = nix::ifaddrs::getifaddrs().unwrap();
for iface in ifaces {
println!("{:#?}", iface);
}
When I do this, it strangely lists eth0 three times. Once with netmask as None, and once with broadcast as None.
Anyone know why it's being listed 3 separate times? Or is it an issue with my WSL config? I'd expect it to only show up once, like in the result of running ip show link.
I've provided the 3 listing below.
InterfaceAddress {
interface_name: "eth0",
flags: IFF_UP | IFF_BROADCAST | IFF_RUNNING | IFF_MULTICAST | IFF_LOWER_UP | IFF_NO_PI | IFF_TUN | IFF_TAP,
address: Some(
SockaddrStorage {
ss: sockaddr_storage {
ss_family: 17,
__ss_align: 140736544452160,
},
},
),
netmask: None,
broadcast: Some(
SockaddrStorage {
ss: sockaddr_storage {
ss_family: 17,
__ss_align: 140736544451856,
},
},
),
destination: None,
}
InterfaceAddress {
interface_name: "eth0",
flags: IFF_UP | IFF_BROADCAST | IFF_RUNNING | IFF_MULTICAST | IFF_LOWER_UP | IFF_NO_PI | IFF_TUN | IFF_TAP,
address: Some(
SockaddrStorage {
ss: sockaddr_storage {
ss_family: 2,
__ss_align: 94107083991267,
},
},
),
netmask: Some(
SockaddrStorage {
ss: sockaddr_storage {
ss_family: 2,
__ss_align: 94107084128296,
},
},
),
broadcast: Some(
SockaddrStorage {
ss: sockaddr_storage {
ss_family: 2,
__ss_align: 94107084192256,
},
},
),
destination: None,
}
InterfaceAddress {
interface_name: "eth0",
flags: IFF_UP | IFF_BROADCAST | IFF_RUNNING | IFF_MULTICAST | IFF_LOWER_UP | IFF_NO_PI | IFF_TUN | IFF_TAP,
address: Some(
SockaddrStorage {
ss: sockaddr_storage {
ss_family: 10,
__ss_align: 94107083991267,
},
},
),
netmask: Some(
SockaddrStorage {
ss: sockaddr_storage {
ss_family: 10,
__ss_align: 94107084128296,
},
},
),
broadcast: None,
destination: None,
}

This is normal. You're not listing interfaces, you're listing interface addresses with getifaddr. You can have multiple addresses per interface. See, e.g., how some of them have ss_family 2, others 10? That's IPv4 and v6 addresses. Compare with the output of ip -brief a or similar.
You probably want if_nameindex instead.

Related

Symfony - switch from php-ampqlib RabbitMQ bundle to messenger - which is the way?

I am trying to change switch to symfony messenger, but documentation doesnt show me way.
Lets have old configuration for php-ampqlib:
mail_queue:
connection: message
exchange_options: { name: 'mail_queue', type: direct }
queue_options: { name: 'mail_queue',arguments: { 'x-dead-letter-exchange': [ 'S', 'mail_queue_failed' ],'x-dead-letter-routing-key': [ 'S', '' ],'x-max-priority': [ 'I',10 ] } }
callback: AppBundle\Consumer\MailQueueConsumer
qos_options: { prefetch_size: 0, prefetch_count: 1, global: false }
mail_queue_failed:
connection: message
exchange_options: { name: 'mail_queue_failed', type: direct }
queue_options: { name: 'mail_queue_failed', arguments: { 'x-message-ttl': [ 'I', 20000 ], 'x-dead-letter-exchange': [ 'S', 'mail_queue' ],'x-dead-letter-routing-key': [ 'S', '' ] } }
callback: AppBundle\Consumer\DoingNothingConsumer
How is the same configuration for Symfony messenger? I have spended a lot of hours without success.
Thank you very much.
D

JQ: A list with multiple values for one key

Using jq, I want to get a list of application names, all versions and server name. The list should not contain information about the latest version.
Input:
{
"software": {
"app_1": {
"0.0.1": {
"properties_1": {
"lang": "en"
},
"server": "vm123-4.domain.com"
},
"0.0.2": {
"properties_2": {
"arch": "x86"
},
"server": "vm123-5.comain.com"
},
"latest_version": "0.0.2"
},
"app_2": {
"1.0.1": {
"properties_2": {
"arch": "x86"
},
"server": "vm333-1.domain.com"
},
"latest_version": "1.0.1"
},
"app_33": {
"0.44.1": {
"properties_1": {
"lang": "en"
},
"properties_2": {
"arch": "x86"
},
"properties_3": {
"boot": "true"
},
"server": "vm888-9.domain.com"
},
"1.2.2": {
"properties_3": {
"boot": "yes"
},
"server": "vm123-4.domain.com"
},
"latest_version": "1.2.2"
}
}
}
Desired output:
"app_1, 0.0.1, vm123-4.domain.com"
"app_1, 0.0.2, vm123-5.comain.com"
"app_2, 1.0.1, vm333-1.comain.com"
"app_33, 0.44.1, vm888-9.comain.com"
"app_33, 1.2.2, vm123-4.comain.com"
My request will only list one version of the app, but not all. I do not know how to do this.
.software | to_entries[] | [(.key), (.value | to_entries[] | select(.key | IN("latest_version") | not))] | "\(.[0]) \(.[1].key) \(.[1].value.server)"
My output:
"app_1 0.0.1 vm123-4.domain.com"
"app_2 1.0.1 vm333-1.domain.com"
"app_33 0.44.1 vm888-9.domain.com"
.software | to_entries[] | "\(.key) \(.value | to_entries[] | select(.key != "latest_version") | "\(.key) \(.value.server)")"
Will produce
"app_1 0.0.1 vm123-4.domain.com"
"app_1 0.0.2 vm123-5.comain.com"
"app_2 1.0.1 vm333-1.domain.com"
"app_33 0.44.1 vm888-9.domain.com"
"app_33 1.2.2 vm123-4.domain.com"
As you can test in this online demo.
Using --raw-output with tabs \t, we can create a column like output:
app_1 0.0.1 vm123-4.domain.com
app_1 0.0.2 vm123-5.comain.com
app_2 1.0.1 vm333-1.domain.com
app_33 0.44.1 vm888-9.domain.com
app_33 1.2.2 vm123-4.domain.com
Demo
jq -r '.software | to_entries[] | .key as $app | .value | to_entries[] | select((.value | objects)) | [$app, .key, .value.server] | #csv'

JQ, two queries, over different part of json, Merge it back

I am trying to extract kubeconfig data with jq.
kubectl config view --raw -o json | jq ...
There is a json produced of this kind:
{
"kind": "Config",
"apiVersion": "v1",
"preferences": {},
"clusters": [
{
"name": "some-name",
"cluster": {
"server": "https://some-url",
"certificate-authority-data": "some-cert"
}
},
{
"name": "another-name",
"cluster": {
"server": "https://another-url",
"certificate-authority-data": "another-cert"
}
}
],
"users": [
{
"name": "some-name",
"user": {
"username": "some-user",
"password": "some-password"
}
},
{
"name": "another-name",
"user": {
"username": "another-user",
"password": "another-password"
}
}
],
"contexts": [],
"current-context": "some-context"
}
Question #1:
For a given name ,"some-name", I'd like to extract json:
{
url: "https://some-url",
cert: "some-cert",
username: "some-user",
password: "some-password"
}
Question #2:
"users" sub-section can have other format
"users": [
{
"name": "...",
"user": {
"exec": {
...
}
Where .user.username or .user.password or both can be missing
In this case overall query should return "{}", even though, "clusters" query/branch has result
Question 3, as a follow up to Jeff Mercado answer:
I want to get all clusters, joined (grouped by) name:
Looking at the manual, https://stedolan.github.io/jq/manual/#Builtinoperatorsandfunctions ,
section "Multiplication, division, modulo: *, /, and %", example:
jq '{"k": {"a": 1, "b": 2}} * {"k": {"a": 0,"c": 3}}' => {"k": {"a": 0, "b": 2, "c": 3}}'
gives presumably right result, assuming "k" is value of "name". So, grouping by "k", merging (*) the results.
I produced following query:
echo "${json}" | jq -r '(.clusters[] | {(.name): {url: .cluster.server, cert: .cluster["certificate-authority-data"]}}) * (.users[] | {(.name): {user: .user.username, password: .user.password}})'
First part returns {"name": {url: cert}}, second part is {"name": {username, password}}
However, result is not merge as in jq Manual, but something else ... product ?
{
"some-name": {
"url": "https://some-url",
"cert": "some-cert",
"user": "some-user",
"password": "some-password"
}
}
{
"another-name": {
"url": "https://another-url",
"cert": "another-cert"
},
"some-name": {
"user": "some-user",
"password": "some-password"
}
}
{
"some-name": {
"url": "https://some-url",
"cert": "some-cert"
},
"another-name": {
"user": "another-user",
"password": "another-password"
}
}
{
"another-name": {
"url": "https://another-url",
"cert": "another-cert",
"user": "another-user",
"password": "another-password"
}
}
Why/what is it ? Kind of following idea of the product ('*') but not of the jq tutorial as I (most likely, incorrectly) understand it
Experimentation:
I have 2 queries now producing partial result.
Let's grab original json (above) in and parse:
read -d '' json << EOF
...
EOF
queries:
echo "${json}" | jq -r '.clusters[] | select(.name=="some-name") | .cluster | {url: .server, cert: .["certificate-authority-data"]}' &&\
echo "${json}" | jq -r '.users[] | select(.name=="some-name") | .user | {user: .username, password: .password}'
Will produce the split output:
{
"url": "https://some-url",
"cert": "some-cert"
}
{
"user": "some-user",
"password": "some-password"
}
Or, with key added for further merge:
echo "${json}" | jq -r '.clusters[] | select(.name=="some-name") | {name: .name, url: .cluster.server, cert: .cluster["certificate-authority-data"]}' &&\
echo "${json}" | jq -r '.users[] | select(.name=="some-name") | {name: .name, user: .user.username, password: .user.password}'
Will produce:
{
"name": "some-name",
"url": "https://some-url",
"cert": "some-cert"
}
{
"name": "some-name",
"user": "some-user",
"password": "some-password"
}
"name" is not needed but can be used as a join operation
So you already know how to get the cluster and user by name separately, first step is to select them both within a single filter:
(.clusters[] | select(.name == $name).cluster), (.users[] | select(.name == $name).user)
This will yield two separate objects, the cluster, then the user. But we want to merge them. There's plenty of ways to do this. You could add them (+) directly or merge them (*) but no real difference there. You'll just want to remap the properties to the names you wanted where needed.
(.clusters[] | select(.name == $name).cluster | {url: .server, cert: ."certificate-authority-data"})
+
(.users[] | select(.name == $name).user | {username, password})
Pass the name in as a parameter to your filter;
$ kubectl config view --raw -o json | jq --arg name some-name '
(.clusters[] | select(.name == $name).cluster | {url: .server, cert: ."certificate-authority-data"})
+
(.users[] | select(.name == $name).user | {username, password})
'
For the second part of your question, if it turns out the mapped user is missing key properties and you want to omit them, just add another select filter to the end to test for those properties and replace with an empty object if nothing is found:
... | select(has("username") and has("password")) // {}
jqplay

JQ only returns one CIDR block from AWS CLI

I am trying to read the CIDR blocks from the VPCs in AWS on the AWS CLI. I will use this in a script when I'm done. I am using jq to parse the info:
aws ec2 describe-vpcs --region=us-east-1 | jq -r '.Vpcs[].CidrBlock'
10.200.3.0/24
However, jq only returns one of the two CIDR blocks in the VPC. This is the original json:
{
"Vpcs": [
{
"CidrBlock": "10.200.3.0/24",
"DhcpOptionsId": "dopt-d0aa95ab",
"State": "available",
"VpcId": "vpc-00de11103235ec567",
"OwnerId": "046480487130",
"InstanceTenancy": "default",
"Ipv6CidrBlockAssociationSet": [
{
"AssociationId": "vpc-cidr-assoc-09f19d81c2e4566b9",
"Ipv6CidrBlock": "2600:1f18:1f7:300::/56",
"Ipv6CidrBlockState": {
"State": "associated"
},
"NetworkBorderGroup": "us-east-1"
}
],
"CidrBlockAssociationSet": [
{
"AssociationId": "vpc-cidr-assoc-0511a5d459f937899",
"CidrBlock": "10.238.3.0/24",
"CidrBlockState": {
"State": "associated"
}
},
{
"AssociationId": "vpc-cidr-assoc-05ad73e8c515a470f",
"CidrBlock": "100.140.0.0/27",
"CidrBlockState": {
"State": "associated"
}
}
],
"IsDefault": false,
"Tags": [
{
"Key": "environment",
"Value": "int01"
},
{
"Key": "Name",
"Value": "company-int01-vpc"
},
{
"Key": "project",
"Value": "company"
}
]
}
]
}
Why does jq only return part of the info I'm after? I need to get all VPC CIDR blocks in the output.
You have two keys CidrBlock and CidrBlockAssociationSet under the Vpcs array.
aws ec2 describe-vpcs --region=us-east-1 |
jq -r '.Vpcs[] | .CidrBlock, .CidrBlockAssociationSet[].CidrBlock'
10.200.3.0/24
10.238.3.0/24
100.140.0.0/27
and this is an invariant solution:
aws ... | jq -r '.. | if type == "object" and has("CidrBlock") then .CidrBlock else empty end'
and, inspired by jq170727's answer, a less expressive form:
aws ... | jq -r '.. | objects | .CidrBlock // empty'
Here is a filter inspired by Dmitry's answer which is slightly shorter: .. | .CidrBlock? | values
Try it online!

DC/OS Marathon constraints hostname list

When I want use
"constraints": [["hostname", "CLUSTER", "192.168.18.6(1|2)"]]
or
"constraints": [["hostname", "CLUSTER", "DCOS-S-0(1|2)"]]
In Marathon app name "/zaslepki/4maxpl" has all the time Waiting status
So I try use attribute - I execute:
[root#DCOS-S-00 etc]# systemctl stop dcos-mesos-slave-public.service
[root#DCOS-S-00 etc]# mesos-slave --work_dir=/var/lib/mesos/slave --attributes=DC:DL01 --master=zk://192.168.18.51:2181,192.168.18.51:2181,192.168.18.53:2181/mesos
WARNING: Logging before InitGoogleLogging() is written to STDERR
I1229 13:16:19.800616 24537 main.cpp:243] Build: 2016-11-07 21:31:04 by
I1229 13:16:19.800720 24537 main.cpp:244] Version: 1.0.1
I1229 13:16:19.800726 24537 main.cpp:251] Git SHA: d5746045ac740d5f28f238dc55ec95c89d2b7cd9
I1229 13:16:19.807195 24537 systemd.cpp:237] systemd version `219` detected
I1229 13:16:19.807232 24537 main.cpp:342] Inializing systemd state
I1229 13:16:19.820071 24537 systemd.cpp:325] Started systemd slice `mesos_executors.slice`
I1229 13:16:19.821051 24537 containerizer.cpp:196] Using isolation: posix/cpu,posix/mem,filesystem/posix,network/cni
I1229 13:16:19.825422 24537 linux_launcher.cpp:101] Using /sys/fs/cgroup/freezer as the freezer hierarchy for the Linux launcher
I1229 13:16:19.826690 24537 main.cpp:434] Starting Mesos agent
2016-12-29 13:16:19,827:24537(0x7f8ecae60700):ZOO_INFO#log_env#726: Client environment:zookeeper.version=zookeeper C client 3.4.8
2016-12-29 13:16:19,827:24537(0x7f8ecae60700):ZOO_INFO#log_env#730: Client environment:host.name=DCOS-S-00
2016-12-29 13:16:19,827:24537(0x7f8ecae60700):ZOO_INFO#log_env#737: Client environment:os.name=Linux
2016-12-29 13:16:19,827:24537(0x7f8ecae60700):ZOO_INFO#log_env#738: Client environment:os.arch=3.10.0-514.2.2.el7.x86_64
2016-12-29 13:16:19,827:24537(0x7f8ecae60700):ZOO_INFO#log_env#739: Client environment:os.version=#1 SMP Tue Dec 6 23:06:41 UTC 2016
2016-12-29 13:16:19,827:24537(0x7f8ecae60700):ZOO_INFO#log_env#747: Client environment:user.name=root
2016-12-29 13:16:19,827:24537(0x7f8ecae60700):ZOO_INFO#log_env#755: Client environment:user.home=/root
2016-12-29 13:16:19,827:24537(0x7f8ecae60700):ZOO_INFO#log_env#767: Client environment:user.dir=/opt/mesosphere/etc
2016-12-29 13:16:19,827:24537(0x7f8ecae60700):ZOO_INFO#zookeeper_init#800: Initiating client connection, host=192.168.18.51:2181,192.168.18.51:2181,192.168.18.53:2181 sessionTimeout=10000 watcher=0x7f8ed221a030 sessionId=0 sessionPasswd=<null> context=0x7f8ebc001ee0 flags=0
I1229 13:16:19.828233 24537 slave.cpp:198] Agent started on 1)#192.168.18.60:5051
2016-12-29 13:16:19,828:24537(0x7f8ec8c49700):ZOO_INFO#check_events#1728: initiated connection to server [192.168.18.51:2181]
I1229 13:16:19.828263 24537 slave.cpp:199] Flags at startup: --appc_simple_discovery_uri_prefix="http://" --appc_store_dir="/tmp/mesos/store/appc" --attributes="DC:DL01" --authenticate_http_readonly="false" --authenticate_http_readwrite="false" --authenticatee="crammd5" --authentication_backoff_factor="1secs" --authorizer="local" --cgroups_cpu_enable_pids_and_tids_count="false" --cgroups_enable_cfs="false" --cgroups_hierarchy="/sys/fs/cgroup" --cgroups_limit_swap="false" --cgroups_root="mesos" --container_disk_watch_interval="15secs" --containerizers="mesos" --default_role="*" --disk_watch_interval="1mins" --docker="docker" --docker_kill_orphans="true" --docker_registry="https://registry-1.docker.io" --docker_remove_delay="6hrs" --docker_socket="/var/run/docker.sock" --docker_stop_timeout="0ns" --docker_store_dir="/tmp/mesos/store/docker" --docker_volume_checkpoint_dir="/var/run/mesos/isolators/docker/volume" --enforce_container_disk_quota="false" --executor_registration_timeout="1mins" --executor_shutdown_grace_period="5secs" --fetcher_cache_dir="/tmp/mesos/fetch" --fetcher_cache_size="2GB" --frameworks_home="" --gc_delay="1weeks" --gc_disk_headroom="0.1" --hadoop_home="" --help="false" --hostname_lookup="true" --http_authenticators="basic" --http_command_executor="false" --image_provisioner_backend="copy" --initialize_driver_logging="true" --ip_discovery_command="/opt/mesosphere/bin/detect_ip" --isolation="posix/cpu,posix/mem" --launcher_dir="/opt/mesosphere/packages/mesos--253f5cb0a96e2e3574293ddfecf5c63358527377/libexec/mesos" --logbufsecs="0" --logging_level="INFO" --master="zk://192.168.18.51:2181,192.168.18.51:2181,192.168.18.53:2181/mesos" --oversubscribed_resources_interval="15secs" --perf_duration="10secs" --perf_interval="1mins" --port="5051" --qos_correction_interval_min="0ns" --quiet="false" --recover="reconnect" --recovery_timeout="15mins" --registration_backoff_factor="1secs" --revocable_cpu_low_priority="true" --sandbox_directory="/mnt/mesos/sandbox" --strict="true" --switch_user="true" --systemd_enable_support="true" --systemd_runtime_directory="/run/systemd/system" --version="false" --work_dir="/var/lib/mesos/slave"
I1229 13:16:19.829263 24537 slave.cpp:519] Agent resources: cpus(*):8; mem(*):6541; disk(*):36019; ports(*):[31000-32000]
I1229 13:16:19.829306 24537 slave.cpp:527] Agent attributes: [ DC=DL01 ]
I1229 13:16:19.829319 24537 slave.cpp:532] Agent hostname: DCOS-S-00
2016-12-29 13:16:19,832:24537(0x7f8ec8c49700):ZOO_INFO#check_events#1775: session establishment complete on server [192.168.18.51:2181], sessionId=0x1593f6a1ef20fce, negotiated timeout=10000
I1229 13:16:19.832623 24548 state.cpp:57] Recovering state from '/var/lib/mesos/slave/meta'
I1229 13:16:19.832695 24547 group.cpp:349] Group process (group(1)#192.168.18.60:5051) connected to ZooKeeper
I1229 13:16:19.832723 24547 group.cpp:837] Syncing group operations: queue size (joins, cancels, datas) = (0, 0, 0)
I1229 13:16:19.832736 24547 group.cpp:427] Trying to create path '/mesos' in ZooKeeper
I1229 13:16:19.834234 24547 detector.cpp:152] Detected a new leader: (id='70')
I1229 13:16:19.834319 24547 group.cpp:706] Trying to get '/mesos/json.info_0000000070' in ZooKeeper
I1229 13:16:19.835002 24547 zookeeper.cpp:259] A new leading master (UPID=master#192.168.18.53:5050) is detected
Failed to perform recovery: Incompatible agent info detected.
------------------------------------------------------------
Old agent info:
hostname: "192.168.18.60"
resources {
name: "ports"
type: RANGES
ranges {
range {
begin: 1
end: 21
}
range {
begin: 23
end: 5050
}
range {
begin: 5052
end: 32000
}
}
role: "slave_public"
}
resources {
name: "disk"
type: SCALAR
scalar {
value: 37284
}
role: "slave_public"
}
resources {
name: "cpus"
type: SCALAR
scalar {
value: 8
}
role: "slave_public"
}
resources {
name: "mem"
type: SCALAR
scalar {
value: 6541
}
role: "slave_public"
}
attributes {
name: "public_ip"
type: TEXT
text {
value: "true"
}
}
id {
value: "8bc3d621-ed8a-4641-88c1-7a7163668263-S9"
}
checkpoint: true
port: 5051
------------------------------------------------------------
New agent info:
hostname: "DCOS-S-00"
resources {
name: "cpus"
type: SCALAR
scalar {
value: 8
}
role: "*"
}
resources {
name: "mem"
type: SCALAR
scalar {
value: 6541
}
role: "*"
}
resources {
name: "disk"
type: SCALAR
scalar {
value: 36019
}
role: "*"
}
resources {
name: "ports"
type: RANGES
ranges {
range {
begin: 31000
end: 32000
}
}
role: "*"
}
attributes {
name: "DC"
type: TEXT
text {
value: "DL01"
}
}
id {
value: "8bc3d621-ed8a-4641-88c1-7a7163668263-S9"
}
checkpoint: true
port: 5051
------------------------------------------------------------
To remedy this do as follows:
Step 1: rm -f /var/lib/mesos/slave/meta/slaves/latest
This ensures agent doesn't recover old live executors.
Step 2: Restart the agent.
[root#DCOS-S-00 etc]# rm -f /var/lib/mesos/slave/meta/slaves/latest
[root#DCOS-S-00 etc]# systemctl start dcos-mesos-slave-public.service
and I use in .json application configuration file
"constraints": [["DC", "CLUSTER", "DL01"]]
Status application is Waiting.....
This is my .json file aplication "/zaslepki/4maxpl"
{
"id": "/zaslepki/4maxpl",
"cmd": null,
"cpus": 0.5,
"mem": 256,
"disk": 0,
"instances": 2,
"constraints": [["hostname", "CLUSTER", "DCOS-S-0(3|4)"]],
"acceptedResourceRoles": [
"slave_public"
],
"container": {
"type": "DOCKER",
"volumes": [],
"docker": {
"image": "arekmax/4maxpl",
"network": "BRIDGE",
"portMappings": [
{
"containerPort": 80,
"hostPort": 0,
"servicePort": 10015,
"protocol": "tcp",
"labels": {}
}
],
"privileged": false,
"parameters": [],
"forcePullImage": false
}
},
"healthChecks": [
{
"path": "/",
"protocol": "HTTP",
"portIndex": 0,
"gracePeriodSeconds": 300,
"intervalSeconds": 30,
"timeoutSeconds": 10,
"maxConsecutiveFailures": 2,
"ignoreHttp1xx": false
}
],
"labels": {
"HAPROXY_GROUP": "external"
},
"portDefinitions": [
{
"port": 10015,
"protocol": "tcp",
"labels": {}
}
]
}
What I do wrong? I find that same problem link but there problem was fixed by use
constraints: [["DC", "CLUSTER", "DL01"]]
You've got a clue in a log:
Invalid attribute key:value pair 'DL01'
Change your attribute to key:value pair e.g., DC:DL01 and it should work. Probably you will need to clean metadata directory because you are changing Agent configuration.
Cluster operator doesnt work with multiple values. You need to pass regular expression so your it should looks like this
"constraints": [["hostname", "LIKE", "192.168.18.6(1|2)"]]

Resources