Ceilometer group by metadata - filter

With ceilometer statistics, is possible filter by grouby with resource_metadata? For example, with instance, group by flavor.name from metadata.
ceilometer statistics -m instance -g resource_metadata[any field]
Thanks.

If you attach metadata with the prefix of metering. to an instance (eg: metering.some_name)
$ nova show <instance_id>
...
| metadata | {"metering.some_name": "some_value"} |
...
Then you can get Ceilometer to aggregate samples and calculate statistics across all instances with the metering.somename metadata that has some_value by using a query of the form:
-q metadata.user_metadata.some_name=some_value
eg:
ceilometer sample-list -m cpu_util -q metadata.user_metadata.some_name=some_value
ceilometer statistics -m cpu_util -q metadata.user_metadata.some_name=some_value -p 60 -a avg

Related

Find sAMAccountName of manager for a user using samaccountname of user as input in Bash

How do we find the sAMAccountName of a users manager with samaccountname of the user as input ? I tried doing in 2 steps where first i'm trying to fetch the users manager details by using manager attribute but that only has the CN of manager in output and then passing the same as input to other ldapsearch query.
However this does not fetch any data ? Is there any other way i can get the sAMAccountName of users manager in bash using users samaccountname ?
Query 1:-
mgr_cn=`ldapsearch -H ldaps://vodaldaps-ala.voda.regn.net -x -w $pass -D "voda\ramesh01" -b "OU=User Accounts,DC=voda,DC=regn,DC=net" "(&(objectclass=user)(samaccountname=john01))" manager | grep manager: | cut -d',' -f1,2 | cut -d'=' -f2 | tr -d '\\' `
echo $mgr_cn
Lambert, Mark (VOD-MUM)
Query 2:-
ldapsearch -v -x -LLL -H ldaps://vodaldaps-ala.voda.regn.net:636 -D 'voda\ramesh01' -w $pass -b "dc=voda,dc=regn,dc=net" "(&(objectClass=user)(cn=$mgr_cn))" sAMAccountName
No Output fetched.
Is your domain part of an AD forest and the manager is on a different domain? That would explain it, since the base DN you're giving it wouldn't be accurate.
Regardless, I think you can simplify this by using the full distinguished name that the manager attribute gives you, rather than trying to extract just the CN portion. Something like this:
mgr_dn=`ldapsearch -H ldaps://vodaldaps-ala.voda.regn.net -x -w $pass -D "voda\ramesh01" -b "OU=User Accounts,DC=voda,DC=regn,DC=net" "(&(objectclass=user)(samaccountname=john01))" manager | grep manager:
echo $mgr_dn
ldapsearch -v -x -LLL -H ldaps://vodaldaps-ala.voda.regn.net:636 -D 'voda\ramesh01' -w $pass -b "$mgr_dn" -s base "(objectClass=*)" sAMAccountName
That last line sets the baseDN to the DN of the manager, and the search scope to base so that it can only return the object at the baseDN (the manager's account).
However, if the manager is on a different domain, that may still not work because you're connecting to port 636, which will only return values for the current domain. You can change that to port 3269, which is the port for the Global Catalog (with SSL), so it returns objects from the entire AD forest.

SNMP: No such object available on this agent at this OID

I am trying to monitor the state of a UPS (NetVision), using the provided mib file.
So, upsBatteryStatus should be .1.3.6.1.2.1.33.1.2.1.0
snmpwalk -c COMMUNITY -v1 192.168.1.10 .1.3.6.1.2.1.33.1.2.1.0
iso.3.6.1.2.1.33.1.2.1.0 = INTEGER: 2
And here comes the tricky part:
snmptranslate -Of SOCOMECUPS-MIB::upsBatteryStatus
.iso.org.dod.internet.private.enterprises.socomecSicon.software.network.netvision.upsObjects.upsBattery.upsBatteryStatus
snmptranslate -On SOCOMECUPS-MIB::upsBatteryStatus
.1.3.6.1.4.1.4555.1.1.1.1.2.1
Its different from .1.3.6.1.2.1.33.1.2.1.0 , and it doesnt respond with a value.
check_snmp -H 192.168.1.10 -C COMMUNITY -o upsBatteryStatus -w 1 -c #3:7 -m /var/lib/mibs/ietf/NetVision-nv6-unix.mib -l "Battery Status: "
External command error: Error in packet
Reason: (noSuchName) There is no such variable name in this MIB.
Failed object: SOCOMECUPS-MIB::upsBatteryStatus
Any ideas why it isnt recongnizes as upsBatteryStatus ?
There seem to be 2 objects with the object name upsBatteryStatus in 2 different MIBs: http://www.oidview.com/mibs/4555/SOCOMECUPS-MIB.html and https://www.rfc-editor.org/rfc/rfc1628 . That explains the different OIDs. Nothing wrong with that. The OID is the true identifier of an object, the name is just for us humans.
As far as the error, I don't know what check_snmp does, so cannot say anything about that. But, have you tried this command?
snmpwalk -c COMMUNITY -v1 192.168.1.10 .1.3.6.1.4.1.4555.1.1.1.1.2.1
Helpful commands:
snmptranslate -Tp -m /usr/share/mibs/ietf/NetVision-nv6-unix.mib
and:
"upsBatteryStatus" "1.3.6.1.2.1.33.1.2.1"
| | |
| | +--upsBattery(2)
| | | |
| | | +-- -R-- EnumVal upsBatteryStatus(1)
| | | | Values: unknown(1), batteryNormal(2), batteryLow(3), batteryDepleted(4)
Nagios check_snmp command that reported the correct value is:
/usr/local/nagios/libexec/check_snmp -H 192.168.1.10 -C COMMUNITY -m /var/lib/mibs/ietf/NetVision-nv6-unix.mib -o upsBatteryStatus -w #0:1 -c #3:7 -l "Battery Status: "
SNMP OK - Battery Status: 2 | 'Battery Status: '=2;1;7;
Thank you for help.

Run cassandra queries from command line

I want to execute cql queries from bash command.
[cqlsh 3.1.8 | Cassandra 1.2.19 | CQL spec 3.0.5 | Thrift protocol 19.36.2]
[root#hostname ~]# /opt/apache-cassandra-1.2.19/bin/cqlsh -k "some_keyspace" -e "SELECT column FROM Users where key=value"
I got:
cqlsh: error: no such option: -e
Options:
--version show program's version number and exit
-h, --help show this help message and exit
-C, --color Always use color output
--no-color Never use color output
-u USERNAME, --username=USERNAME
Authenticate as user.
-p PASSWORD, --password=PASSWORD
Authenticate using password.
-k KEYSPACE, --keyspace=KEYSPACE
Authenticate to the given keyspace.
-f FILE, --file=FILE Execute commands from FILE, then exit
-t TRANSPORT_FACTORY, --transport-factory=TRANSPORT_FACTORY
Use the provided Thrift transport factory function.
--debug Show additional debugging information
--cqlversion=CQLVERSION
Specify a particular CQL version (default: 3.0.5).
Examples: "2", "3.0.0-beta1"
-2, --cql2 Shortcut notation for --cqlversion=2
-3, --cql3 Shortcut notation for --cqlversion=3
Any suggestions ?
First of all, you should seriously consider upgrading. You are missing out on a lot of new features and bug fixes.
Secondly, with cqlsh in Cassandra 1.2 you can use the -f flag to specify a file containing cql statements:
$ echo "use system_auth; SELECT role,is_superuser FROM roles WHERE role='cassandra';" > userQuery.cql
$ bin/cqlsh -u aploetz -p reindeerFlotilla -f userQuery.cql
role | is_superuser
-----------+--------------
cassandra | True
(1 rows)
You can use -f to execute from a file or SOURCE once you start CQLSH. I don't think -e is a valid option with that version.
It's bit dirty and unstable, but here is the answer:
/opt/apache-cassandra-1.2.19/bin/cqlsh -k "keyspace" -f /path/to/file.cql > /path/to/output.txt
tail -2 /path/to/output.txt | head -1 > /path/to/output-value.txt

Monetdb - tables size in the database

I've loaded .tbl files in the tables, now how I can see the total space used on the disk by the database?
I'm using Fedora
The disk footprint can be assessed using the (Linux) command 'du' on
the dbfarm directory or to run the query 'select * from storage();
Source: http://www.monetdb.org/Documentation/Userguide/diskspace
You can try as follows:
mclient -d dwh -f tab -s "select location from storage() where table='name_of_a_table';" | xargs -i du -m /var/monetdb5/dbfarm/dwh/bat/{}.tail | cut -f1 | paste -sd+ | bc

how to ping each ip in a file?

I have a file named "ips" containing all ips I need to ping. In order to ping those IPs, I use the following code:
cat ips|xargs ping -c 2
but the console show me the usage of ping, I don't know how to do it correctly. I'm using Mac os
You need to use the option -n1 with xargs to pass one IP at time as ping doesn't support multiple IPs:
$ cat ips | xargs -n1 ping -c 2
Demo:
$ cat ips
127.0.0.1
google.com
bbc.co.uk
$ cat ips | xargs echo ping -c 2
ping -c 2 127.0.0.1 google.com bbc.co.uk
$ cat ips | xargs -n1 echo ping -c 2
ping -c 2 127.0.0.1
ping -c 2 google.com
ping -c 2 bbc.co.uk
# Drop the UUOC and redirect the input
$ xargs -n1 echo ping -c 2 < ips
ping -c 2 127.0.0.1
ping -c 2 google.com
ping -c 2 bbc.co.uk
With ip or hostname in each line of ips file:
( while read ip; do ping -c 2 $ip; done ) < ips
You can also change timeout, with -W flag, so if some hosts isn'up, it wont lock your script for too much time. Also -q for quiet output is useful in this case.
( while read ip; do ping -c1 -W1 -q $ip; done ) < ips
If the file is 1 ip per line (and it's not overly large), you can do it with a for loop:
for ip in $(cat ips); do
ping -c 2 $ip;
done
You could use fping. It also does that in parallel and has script friendly output.
$ cat ips | xargs fping -q -C 3
10.xx.xx.xx : 201.39 203.62 200.77
10.xx.xx.xx : 288.10 287.25 288.02
10.xx.xx.xx : 187.62 187.86 188.69
...
With GNU Parallel you would do:
parallel -j0 ping -c 2 {} :::: ips
This will run as many jobs in parallel as you have ips or processes.
It also makes sure the output from different jobs are not mixed together, so if you use the output you are guaranteed that you will not get half-a-line from two different jobs.
GNU Parallel is a general parallelizer and makes is easy to run jobs in parallel on the same machine or on multiple machines you have ssh access to.
If you have 32 different jobs you want to run on 4 CPUs, a straight forward way to parallelize is to run 8 jobs on each CPU:
GNU Parallel instead spawns a new process when one finishes - keeping the CPUs active and thus saving time:
Installation
If GNU Parallel is not packaged for your distribution, you can do a personal installation, which does not require root access. It can be done in 10 seconds by doing this:
(wget -O - pi.dk/3 || curl pi.dk/3/ || fetch -o - http://pi.dk/3) | bash
For other installation options see http://git.savannah.gnu.org/cgit/parallel.git/tree/README
Learn more
See more examples: http://www.gnu.org/software/parallel/man.html
Watch the intro videos: https://www.youtube.com/playlist?list=PL284C9FF2488BC6D1
Walk through the tutorial: http://www.gnu.org/software/parallel/parallel_tutorial.html
Sign up for the email list to get support: https://lists.gnu.org/mailman/listinfo/parallel
Try doing this :
cat ips | xargs -i% ping -c 2 %
As suggested by #Lupus you can use "fping", but the output is not human friendly - it will scroll out of your screen in few seconds laving you with no trace as of what is going on. To address this I've just released ping-xray. I tried to make it as visual as possible under ascii terminal plus it creates CSV logs with exact millisecond resolution for all targets.
https://dimon.ca/ping-xray/
Hope you'll find it helpful.

Resources