Created
March 5, 2022 23:32
-
-
Save cameroncking/f67b27cfe0eddd6e88824b49f3cbbb7c to your computer and use it in GitHub Desktop.
Puppet Facts for Client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# Client Xenon Product Facts | |
# Cameron King <http://cameronking.me> | |
# Version 1.01 - add magento and wordpress counts | |
# Version 1.00 - initial version | |
use warnings; | |
use strict; | |
my $VERSION = 1.01; | |
my %facts = (); | |
sub dpkgGetVersion; #s = (s:pkg) | |
sub whichGetPath; #s = (s:binary) | |
$facts{"zl_product_facts"} = $VERSION; | |
$facts{"zl_security"} = dpkgGetVersion "client-xenon-security"; | |
$facts{"zl_postgresql"} = dpkgGetVersion "client-xenon-postgresql"; | |
$facts{"zl_ftp"} = dpkgGetVersion "client-xenon-ftp"; | |
$facts{"zl_apache"} = dpkgGetVersion "client-xenon-apache"; | |
$facts{"zl_apache"} = "other" if(!exists($facts{"zl_apache"}) && whichGetPath "apache2ctl"); | |
$facts{"zl_mysql"} = dpkgGetVersion "client-xenon-mysql"; | |
$facts{"zl_mysql"} = "other" if(!exists($facts{"zl_mysql"}) && whichGetPath "mysqld"); | |
$facts{"zl_memcached"} = dpkgGetVersion "memcached"; | |
$facts{"zl_redis"} = dpkgGetVersion "redis"; | |
my @magentos = glob "/www/sites/*/files/html/app/etc/local.xml"; | |
$facts{"zl_apache_magento"} = $#magentos+1 if $#magentos >= 0; | |
my @wordpresses = glob "/www/sites/*/files/html/wp-config.php"; | |
$facts{"zl_apache_wordpress"} = $#wordpresses+1 if $#wordpresses >= 0; | |
my @dbmagentos = glob "/var/lib/mysql/*/mage_core_config_data.frm"; | |
$facts{"zl_mysql_magento"} = $#dbmagentos+1 if $#dbmagentos >= 0; | |
my @dbwordpresses = glob "/var/lib/mysql/*/wp_options.frm"; | |
$facts{"zl_mysql_wordpress"} = $#dbwordpresses+1 if $#dbwordpresses >= 0; | |
print map { $facts{$_}?"$_=$facts{$_}\n":"" } keys %facts; | |
sub dpkgGetVersion { | |
my $pkg = shift; | |
$pkg =~ s/[^a-zA-Z0-9\-_]//g; | |
return "" unless "$pkg"; | |
my $out = `dpkg -s $pkg 2>/dev/null`; | |
$out =~ /^Version:\s+([0-9a-zA-Z\-\.]+)/m; | |
my $ver = ""; | |
$ver = $1 if defined $1; | |
chomp $ver; | |
return $ver if $out =~ /^Status:+.*\sinstalled.*$/m; | |
return ""; | |
} | |
sub whichGetPath { | |
my $binary = shift; | |
$binary =~ s/[^a-zA-Z0-9\-_]//g; | |
return "" unless "$binary"; | |
my $out = `which $binary 2>/dev/null`; | |
chomp $out; | |
return $out; | |
} | |
# This software is released under the ISC License. | |
# | |
# Copyright (c) 2013, Cameron King [email protected] | |
# | |
# Permission to use, copy, modify, and/or distribute this software for any | |
# purpose with or without fee is hereby granted, provided that the above | |
# copyright notice and this permission notice appear in all copies. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH | |
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY | |
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | |
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | |
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR | |
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | |
# PERFORMANCE OF THIS SOFTWARE. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment