https://www.puppet.com/community logo
Join Slack
Powered by
# puppet
  • j

    John Ratliff

    10/12/2022, 5:54 PM
    There is a postgres process that seems to say puppetdb in the process list
  • j

    John Ratliff

    10/12/2022, 5:57 PM
    curl <http://localhost:8080/pdb/query/v4/nodes>
    This seems to list a lot of things. Is that what you're referring to?
  • n

    natemccurdy

    10/12/2022, 6:02 PM
    I’m not sure your version of PuppetDB is new enough to support the PQL query syntax, but something like this is what you’d want to find nodes that haven’t checked in since X days: https://puppet.com/docs/puppetdb/5.2/api/query/examples-pql.html#timestamp-filtering
  • b

    bastelfreak

    10/12/2022, 6:03 PM
    for query examples, also take a look at https://voxpupuli.org/docs/pql_queries/ . If you write your own query, let me know and I will add it to the list (or send us a PR)
  • n

    natemccurdy

    10/12/2022, 6:04 PM
    curl -X GET <http://localhost:8080/pdb/query/v4> --data-urlencode 'query=nodes[certname] { report_timestamp <= "2022-10-05 00:00:00" }'
  • n

    natemccurdy

    10/12/2022, 6:04 PM
    curl -X GET <http://localhost:8080/pdb/query/v4> --data-urlencode 'query=nodes[certname] { report_timestamp <= "2022-10-05 00:00:00" }'
  • j

    John Ratliff

    10/12/2022, 6:17 PM
    puppet query "nodes[certname,report_timestamp] { report_timestamp >= '$(date --date '7 days ago' +'%Y-%m-%dT%H:%M:%S')' }"
    This seems like what I want. Thanks.
  • j

    John Ratliff

    10/12/2022, 6:17 PM
    Doesn't even need the report_timestamp in the nodes object, that was just error checking
  • v

    vchepkov

    10/12/2022, 6:18 PM
    we use
    catalog_timestamp
    instead
  • j

    John Ratliff

    10/12/2022, 6:19 PM
    Because that's the last time puppet successfully ran as opposed to just checkin?
  • v

    vchepkov

    10/12/2022, 6:19 PM
    Copy code
    old_timestamp=$(date -u -d '-7 days' -Isec)
    /opt/puppetlabs/bin/puppet-query "nodes[certname]{catalog_timestamp < \"$old_timestamp\"}" | jq -r '.[].certname'
  • v

    vchepkov

    10/12/2022, 6:21 PM
    I guess one could use no-report setting on agent
  • j

    John Ratliff

    10/12/2022, 6:22 PM
    I doubt we are doing that here, but yes, that could be a concern. This should be good enough. Thanks.
    puppet query "nodes[certname]{catalog_timestamp > '$(date -u -d '-7 days' -Isec)'}" | jq -r '.[].certname' | sort > active_puppet_servers.txt
  • l

    Lumiere

    10/12/2022, 9:58 PM
    that nodes endpoint is how I do half my reporting / alerting for nodes not checking in
  • w

    William Myers

    10/12/2022, 11:33 PM
    is this syntactically correct?
    Copy code
    if $::osfamily =~ '(Redhat|Debian)' {
  • w

    William Myers

    10/12/2022, 11:33 PM
    is this syntactically correct?
    Copy code
    if $::osfamily =~ '(Redhat|Debian)' {
  • w

    William Myers

    10/12/2022, 11:35 PM
    hmm, the escape positioning is throwing me off some.
    Copy code
    if $trusted['certname'] =~ /^www(\d+)\./ {
      notice("Welcome to web server number $1.")
    }
  • n

    natemccurdy

    10/12/2022, 11:43 PM
    It’s syntactically correct, but won’t do what you think it will since you’re comparing that to a String rather than a Regex
  • w

    William Myers

    10/12/2022, 11:43 PM
    got it,
    Copy code
    if $::osfamily =~ /(Debian|RedHat)/ {
  • n

    natemccurdy

    10/12/2022, 11:46 PM
    Copy code
    if $facts['os']['family'] in ["Debian", "RedHat"] {
    
    }
    I like
    in
    for checking multiple strings, personally.
  • n

    natemccurdy

    10/12/2022, 11:46 PM
    if $facts['os']['family'] in ["Debian", "RedHat"]
    I like
    in
    for checking multiple strings, personally.
  • n

    natemccurdy

    10/12/2022, 11:46 PM
    Copy code
    if $facts['os']['family'] in ["Debian", "RedHat"] {
    
    }
    I like
    in
    for checking multiple strings, personally.
  • n

    natemccurdy

    10/12/2022, 11:46 PM
    It’s syntactically correct, but won’t do what you think it will since you’re comparing that to a String rather than a Regex
  • w

    William Myers

    10/12/2022, 11:47 PM
    What's the functional difference between this example and the prior one I had hacked together?
  • n

    natemccurdy

    10/12/2022, 11:47 PM
    No functional difference. But I find it simpler to add strings to an array than to combine regexes with
    |
    .
  • n

    natemccurdy

    10/12/2022, 11:48 PM
    Well, the other change is to use the
    $facts
    hash. That has a functional difference in that it’s more stable across Puppet versions (especially future versions).
    ➕ 1
  • g

    glee

    10/12/2022, 11:49 PM
    you would probably also want to put anchors on the regex version eg:
    Copy code
    if $facts['os'['family'] =~ /^(Debian|RedHat)$/ {
    ie: to match
    Debian
    or
    RedHat
    exactly (whereas w/out anchors it could match
    someDebianwithsuffixtrailing
    etc
    ➕ 1
  • g

    glee

    10/12/2022, 11:50 PM
    +1 what Nate said about syntax to reference facts
  • n

    natemccurdy

    10/12/2022, 11:50 PM
    Oh! Yeah, thanks @glee. Thanks a very important functional difference. Your regex would’ve matched “foobarDebianlkjasd”. But the
    in
    operator does full-string comparison.
    ➕ 1
  • w

    William Myers

    10/12/2022, 11:50 PM
    Ahhhhhhh yea
1...195196197...428Latest