I have install mcollective with activemq but when i run following command it ran successfully but result is blank, i want to see report output.
[root#vsoslp01 tmp]# mco find
vsopspss01
vsopsmgs01
[root#vsoslp01 tmp]# mco facts architecture
Report for fact: architecture
Finished processing 2 / 2 hosts in 293.91 ms
Installed plugins
[root#vsoslp01 tmp]# mco plugin doc
Please specify a plugin. Available plugins are:
Agents:
puppet Run Puppet agent, get its status, and enable/disable it
rpcutil General helpful actions that expose stats and internals to SimpleRPC clients
Aggregate:
average Displays the average of a set of numeric values
boolean_summary Aggregate function that will transform true/false values into predefined strings.
sum Determine the total added value of a set of values
summary Displays the summary of a set of results
Data Queries:
agent Meta data about installed MColletive Agents
fstat Retrieve file stat data for a given file
puppet Information about Puppet agent state
resource Information about Puppet managed resources
Discovery Methods:
flatfile Flatfile based discovery for node identities
mc MCollective Broadcast based discovery
stdin STDIN based discovery for node identities
Validator Plugins:
array Validates that a value is included in a list
ipv4address Validates that a value is an ipv4 address
ipv6address Validates that a value is an ipv6 address
length Validates that the length of a string is less or equal to a specified value
puppet_resource Validates the validity of a Puppet resource type and name
puppet_server_address Validates that a string is a valid Puppet Server and Port for the Puppet agent
puppet_tags Validates that a comma seperated list of tags are valid Puppet class names
puppet_variable Validates that a variable name is a valid Puppet name
regex Validates that a string matches a supplied regular expression
shellsafe Validates that a string is shellsafe
typecheck Validates that a value is of a certain type
EDIT:
[root#vsoslp01 logs]# mco inventory vsopspss01
Inventory for vsopspss01:
Server Statistics:
Version: 2.4.1
Start Time: Tue Feb 18 13:40:58 -0500 2014
Config File: /etc/mcollective/server.cfg
Collectives: mcollective
Main Collective: mcollective
Process ID: 7694
Total Messages: 14
Messages Passed Filters: 14
Messages Filtered: 0
Expired Messages: 0
Replies Sent: 13
Total Processor Time: 0.32 seconds
System Time: 0.09 seconds
Agents:
discovery puppet rpcutil
Data Plugins:
agent fstat puppet
resource
Configuration Management Classes:
No classes applied
Facts:
mcollective => 1
Did you populate the facts file? MCollective reads a yaml file contianing all the facts. If it's empty then it won't see any facts.
Populating the facts file
Have you applied Puppet manifests using the puppet-apply command? Does querying inventory on those systems return anything at all?
$ mco inventory vsopspss01
Related
Network guy that's new to Python and programming and found this ciscoconfparse library that looks to have some pretty useful features. I'm running into an issue that I'm sure is something basic, but haven't figured it out. I'm trying to pull snmp config from a router to create a config set to remove v2 configs. Using netmiko to grab output of "show run | in snmp" then parse it. The config that comes back shows as one line. When using ciscoconfparse statements to delete some lines, it deletes everything (assuming because it is only one line) so I have nothing left to build.
in all examples online, sample config looks like this and the functions work as it is multiple lines.
conf=[
'access-list dmz_inbound extended deny udp object training-network any4 eq snmp',
'snmp-server host inside 10.10.10.10 poll community ***** version 2c',
'snmp-server host inside 10.20.20.20 poll community ***** version 2c',
'no snmp-server location',
'no snmp-server contact',
'snmp-server community *****',
'!'
]
when I actually pull config from a router, it looks like this with newline characters but gets parsed as 1 line:
'access-list testNada extended permit udp host 10.10.10.10 eq snmp host 10.20.10.10 eq snmp \nsnmp-server host inside 10.11.11.11 community ***** version 2c\nsnmp-server host inside 10.5.5.5 poll community ***** version 2c\nno snmp-server location\nno snmp-server contact\nsnmp-server community *****\n']
snippet of code I'm running. the delete line statements delete the whole config snip rather than just the line matching the arg.
conf = [ssh.send_command("show run | include snmp")]
parse = CiscoConfParse(conf)
parse.delete_lines('no snmp-server')
parse.delete_lines('access-list')
newConf = (parse.replace_lines('snmp', 'no snmp',excludespec='v3'))
ssh.send_config_set(newConf)
how do I get the config pulled directly from the router to show as multi-line so I can use the ciscoconfparse functions?
You are passing a string to CiscoConfParse instead of a list.
Try the below:
conf = [ssh.send_command("show run | include snmp")]
# this will change your string into a list
formatted_output = conf.splitlines()
parse = CiscoConfParse(formatted_output)
parse.delete_lines('no snmp-server')
parse.delete_lines('access-list')
newConf = (parse.replace_lines('snmp', 'no snmp',excludespec='v3'))
Explanation: Netmiko will return a string (/n means a new line, but it's still a string). When you use splitlines - it will transfer your string into a list (each line will be a new element)
was able to get it to work by iterating over the list returned by netmiko, which returned a 'list in a list'. basically it was a list that had one index that happened to be the list containing the config.
newConf=[]
for i in conf:
newConf.append(i.split("\n"))
which returned
[['access-list testNada extended permit udp host 10.10.3.10 eq snmp host 10.10.10.10 eq snmp ', 'snmp-server host inside 10.4.233.8 community ***** version 2c', ....]]
then ran it through the parser for index 0.
parse = CiscoConfParse(newConf[0])
which resulted in multiple lines and I could use the delete_lines and replace_lines functions to produce the negated config I want to send back to my devices:
['no snmp-server host inside 10.4.233.8 community ***** version 2c', 'no snmp-server host inside 10.3.25.17 poll community ***** version 2c',...]]
I need to insert multiple facts on many machines(100+) based on its hostname. All the machines get a single app deployed but the app configuration differs and also machines form part of different clusters. I am trying to find the right approach to implement this. One approach I found in How can I create a custom :host_role fact from the hostname? wherein there is a condition in facter add code block to check for hostname.
I was also thinking if there is a way to add multiple facts in one facter add call instead of having 1 per facter as that way I can logically organize my code on cluster/machines instead of facts.
Example:
Machine1 and its facts:
clustername: C1
Java version: 1.8.60
ProcessRuns: 3
Machine2 and its facts:
clustername: C1
Java version: 1.8.60
ProcessRuns: 1
Machine3 and its facts:
clustername: C2
Java version: 1.9.00
ProcessRuns: 1
Machine4 and its facts:
clustername: C2
Java version: 1.9.00
ProcessRuns: 2
Machine5 and its facts:
clustername: C3
Java version: 1.9.60
ProcessRuns: 1
I did not find any way to have multiple facts in 1 facter.add call so went with 1 call per fact I wanted to add.
The fact file finally looks something like this:
when "Machine1"
Facter.add(:processcount) do
setcode do
3
end
end
when "Machine2", "Machine3", "Machine5"
Facter.add(:processcount) do
setcode do
1
end
end
I want to just see the total number of keys available in Azure Redis cache that matches the given pattern. I tried the following command it is showing the count after displaying all the keys (which caused server load), But I need only the count.
>SCAN 0 COUNT 10000000 MATCH "{UID}*"
Except command SCAN, the command KEYS pattern can return the same result as your current command SCAN 0 COUNT 10000000 MATCH "{UID}*".
However, for your real needs to get the number of keys matching a pattern, there is an issue add COUNT command from the Redis offical GitHub repo which had answered by the author antirez for you, as the content below.
Hi, KEYS is only intended for debugging since it is O(N) and performs a full keyspace scan. COUNT has the same problem but without the excuse of being useful for debugging... (since you can simply use redis-cli keys ... | grep ...). So feature not accepted. Thanks for your interest.
So you can not directly get the count of KEYS pattern, but there are some possible solutions for you.
Count the keys return from command KEYS pattern in your programming language for the small number of keys with a pattern, like doing redis-cli KEYS "{UID}*" | wc -l on the host server of Redis.
To use the command EVAL script numkeys key \[key ...\] arg \[arg ...\] to run a Lua script to count the keys with pattern, there are two scripts you can try.
2.1. Script 1
return #redis.call("keys", "{UID}*")
2.2. Script 2
return table.getn(redis.call('keys', ARGV[1]))
The completed command in redis-cli is EVAL "return table.getn(redis.call('keys', ARGV[1]))" 0 {UID}*
I am using a Hiera hash to hold some token values which are host-specific. the keys within the hash correspond to the hostname/certname of the node(s) that'll be classified with the profile module that calls the hash value. However, when I apply the module, the value which corresponds to the hash key for the host is always null. Here's the code I'm working with.
in hiera-file.yaml
token_lookup:
host-name1: 'abcdef123'
host-name2: 'abbcde456'
and in profile.pp
$_tokens = hiera_hash('token_lookup', undef, 'hiera-file')
$_specific_token = $_tokens["${::hostname}"] <== never gets a value
I'm certain that the hostname matches the key in the hash. The question is, what's the right syntax here for getting the value from the hiera-file to populate properly? Thank you in advance for the advice.
edit: I believe I have discovered an issue when the hash key has a literal '-' character in it, as many hostnames do. I updated the hash to show keys with dashes in it, and should now ask a more specific question: I see dozens of articles about how to escape characters in the values of hashes by using double quotes, but I don't see anything - even on yaml.org - about how to escape the character if it appears as part of the key. Any tips on this issue? A YAML parser shows that this is valid syntactically, but I believe it is treating the '-' as a collection marker instead of a literal character.
Your code is correct, I test it as below, seems it didn't target the right yaml file in your environment. Check the hierarchy setting, and put the token key-value in the right place.
If I put the yaml file to global.yaml(If hiera can't find the key, it will always go to the last one in my hiera.yaml setting)
I rebuilt it with simplest setting:
$ cat /etc/hiera.yaml:
---
:backends:
- yaml
:hierarchy:
- defaults
- "%{clientcert}"
- "%{environment}"
- global
:yaml:
# datadir is empty here, so hiera uses its defaults:
# - /var/lib/hiera on *nix
# - %CommonAppData%\PuppetLabs\hiera\var on Windows
# When specifying a datadir, make sure the directory exists.
:datadir:
$ cat /var/lib/hiera/global.yaml
token_lookup:
host-name1: 'abcdef123'
host-name2: 'abbcde456'
$ cat profile.pp
$_tokens = hiera_hash('token_lookup', undef, 'hiera-file')
notice ("tokens is $_tokens")
$_specific_token = $_tokens["${::hostname}"]
notice ("token is $_specific_token ")
Then I run puppet apply, I can see the result
$ FACTER_hostname='host-name1' puppet apply profile.pp --hiera_config /etc/hiera.yaml
Notice: Scope(Class[main]): tokens is host-name1abcdef123host-name2abbcde456
Notice: Scope(Class[main]): token is abcdef123
Notice: Compiled catalog for host-name1 in environment production in 0.04 seconds
Notice: Finished catalog run in 0.07 seconds
$ FACTER_hostname='host-name2' puppet apply profile.pp --hiera_config /etc/hiera.yaml
Notice: Scope(Class[main]): tokens is host-name1abcdef123host-name2abbcde456
Notice: Scope(Class[main]): token is abbcde456
Notice: Compiled catalog for host-name2 in environment production in 0.04 seconds
Notice: Finished catalog run in 0.02 seconds
root#ac976d6d79fb:~#
I think hiera_hash is not what you want.
hiera_hash:
Uses a hash merge lookup. Expects every value in the hierarchy for a given key to be a hash, and merges the top-level keys in each hash into a single hash. Note that this does not do a deep-merge in the case of nested structures.
Change:
$_tokens = hiera_hash('token_lookup', undef, 'hiera-file')
to
$_tokens = hiera('token_lookup', {}) #it will create empty hash if it couldn't find 'token_lookup' variable.
Please also check the following example:
# /etc/puppet/hieradata/appservers.yaml
---
proxies:
- hostname: lb01.example.com
ipaddress: 192.168.22.21
- hostname: lb02.example.com
ipaddress: 192.168.22.28
# Get the structured data:
$proxies = hiera('proxies')
# Index into the structure:
$use_ip = $proxies[1]['ipaddress'] # will be 192.168.22.28
Sometimes Syslog send line like that :
Aug 12 20:35:57 server sshd[15984]: last message repeated 2 times
I know that we can disable it, in the rsyslog config file :
$RepeatedMsgReduction off
Source : here
That config disable this feature on all syslog facilities.
But my question is : is there any way to disable this feature on only a specific facility (local1 for example) ?
Thanks !
No, according to the manual this option only accepts values on and off. Likewise, the source code only documents these two values:
int bReduceRepeatMsgs; /* reduce repeated message - 0 - no, 1 - yes */