1
0
mirror of https://github.com/Yubico/yubikey-val.git synced 2025-02-12 15:54:27 +01:00

Cosmetic changes.

- refactor whitespace for munin plugins written in php.

- change spaces into tabs and fix brackets mostly.
This commit is contained in:
Jean Paul Galea 2015-09-07 16:20:58 +02:00
parent a0e3715dbb
commit ed6fb6cbb3
4 changed files with 190 additions and 168 deletions

View File

@ -28,56 +28,65 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set_include_path(get_include_path() . PATH_SEPARATOR . set_include_path(get_include_path() . PATH_SEPARATOR . "/etc/yubico/val:/usr/share/yubikey-val");
"/etc/yubico/val:/usr/share/yubikey-val");
require_once 'ykval-config.php'; require_once 'ykval-config.php';
function url2shortname ($url) { function url2shortname ($url)
if (preg_match("/^[^\/]+\/\/([a-z0-9-]+)/", $url, $name)==0){ {
echo "Cannot match URL hostname: " . $url . "\n"; if (preg_match("/^[^\/]+\/\/([a-z0-9-]+)/", $url, $name) == 0)
exit (1); {
} echo "Cannot match URL hostname: " . $url . "\n";
exit(1);
}
return $name[1]; return $name[1];
} }
$ksms = otp2ksmurls ("ccccccccfnkjtvvijktfrvvginedlbvudjhjnggndtck", 16); $ksms = otp2ksmurls ("ccccccccfnkjtvvijktfrvvginedlbvudjhjnggndtck", 16);
$shortksms = array_map("url2shortname", $ksms); $shortksms = array_map("url2shortname", $ksms);
if ($argc==2 && strcmp($argv[1], "autoconf") == 0) { if ($argc == 2 && strcmp($argv[1], "autoconf") == 0)
print "yes\n"; {
exit (0); print "yes\n";
exit(0);
} }
if ($argc==2 && strcmp($argv[1], "config") == 0) { if ($argc == 2 && strcmp($argv[1], "config") == 0)
{
echo "multigraph ykval_ksmlatency\n";
echo "graph_title KSM latency\n";
echo "graph_vlabel Average KSM Decrypt Latency (seconds)\n";
echo "graph_category ykval\n";
echo "graph_width 400\n";
echo "multigraph ykval_ksmlatency\n"; foreach ($shortksms as $shortksm)
echo "graph_title KSM latency\n"; {
echo "graph_vlabel Average KSM Decrypt Latency (seconds)\n"; echo "${shortksm}_avgwait.label ${shortksm}\n";
echo "graph_category ykval\n"; echo "${shortksm}_avgwait.type GAUGE\n";
echo "graph_width 400\n"; echo "${shortksm}_avgwait.info Average wait time for KSM decrypt\n";
echo "${shortksm}_avgwait.min 0\n";
echo "${shortksm}_avgwait.draw LINE1\n";
}
foreach ($shortksms as $shortksm) { exit(0);
echo "${shortksm}_avgwait.label ${shortksm}\n";
echo "${shortksm}_avgwait.type GAUGE\n";
echo "${shortksm}_avgwait.info Average wait time for KSM decrypt\n";
echo "${shortksm}_avgwait.min 0\n";
echo "${shortksm}_avgwait.draw LINE1\n";
}
exit (0);
} }
echo "multigraph ykval_ksmlatency\n"; echo "multigraph ykval_ksmlatency\n";
foreach ($ksms as $ksm) { foreach ($ksms as $ksm)
$shortksm = url2shortname ($ksm); {
$time = `curl --silent --write-out '%{time_total}' --max-time 3 '$ksm' -o /dev/null`; $shortksm = url2shortname ($ksm);
if (preg_match("/^3\./", $time)) { $time = `curl --silent --write-out '%{time_total}' --max-time 3 '$ksm' -o /dev/null`;
$time = "timeout";
} if (preg_match("/^3\./", $time))
if (preg_match("/^0\.000/", $time)) { {
$time = "error"; $time = "timeout";
} }
echo "${shortksm}_avgwait.value $time\n";
if (preg_match("/^0\.000/", $time))
{
$time = "error";
}
echo "${shortksm}_avgwait.value $time\n";
} }

View File

@ -28,63 +28,69 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set_include_path(get_include_path() . PATH_SEPARATOR . set_include_path(get_include_path() . PATH_SEPARATOR . "/etc/yubico/val:/usr/share/yubikey-val");
"/etc/yubico/val:/usr/share/yubikey-val");
require_once 'ykval-config.php'; require_once 'ykval-config.php';
require_once 'ykval-db.php'; require_once 'ykval-db.php';
function url2shortname ($url) { function url2shortname ($url)
if (preg_match("/^[^\/]+\/\/([a-z0-9-]+)/", $url, $name)==0){ {
echo "Cannot match URL hostname: " . $url . "\n"; if (preg_match("/^[^\/]+\/\/([a-z0-9-]+)/", $url, $name)==0)
exit (1); {
} echo "Cannot match URL hostname: " . $url . "\n";
return $name[1]; exit(1);
}
return $name[1];
} }
if ($argc==2 && strcmp($argv[1], "autoconf") == 0) { if ($argc == 2 && strcmp($argv[1], "autoconf") == 0)
{
print "yes\n"; print "yes\n";
exit (0); exit(0);
} }
$urls = $baseParams['__YKVAL_SYNC_POOL__']; $urls = $baseParams['__YKVAL_SYNC_POOL__'];
$shortnames = array_map("url2shortname", $urls); $shortnames = array_map("url2shortname", $urls);
if ($argc==2 && strcmp($argv[1], "config") == 0) { if ($argc==2 && strcmp($argv[1], "config") == 0)
{
echo "graph_title YK-VAL queue size\n";
echo "graph_vlabel sync requests in queue\n";
echo "graph_category ykval\n";
echo "graph_title YK-VAL queue size\n"; foreach ($shortnames as $shortname)
echo "graph_vlabel sync requests in queue\n"; {
echo "graph_category ykval\n"; echo "queuelength_${shortname}.label sync ${shortname}\n";
echo "queuelength_${shortname}.draw AREASTACK\n";
echo "queuelength_${shortname}.type GAUGE\n";
}
foreach ($shortnames as $shortname) { exit(0);
echo "queuelength_${shortname}.label sync ${shortname}\n";
echo "queuelength_${shortname}.draw AREASTACK\n";
echo "queuelength_${shortname}.type GAUGE\n";
}
exit (0);
} }
$db = Db::GetDatabaseHandle($baseParams, 'ykval-munin-queuelength'); $db = Db::GetDatabaseHandle($baseParams, 'ykval-munin-queuelength');
if (!$db->connect()) { if (!$db->connect())
logdie($myLog, 'ERROR Database connect error (1)'); logdie($myLog, 'ERROR Database connect error (1)');
}
$res = $db->customQuery('select server,count(server) as count from queue group by server'); $res = $db->customQuery('select server,count(server) as count from queue group by server');
if ($res) { if ($res)
$r = $res->fetchAll(PDO::FETCH_ASSOC); $r = $res->fetchAll(PDO::FETCH_ASSOC);
} else { else
logdie($myLog, 'ERROR getting data from db'); logdie($myLog, 'ERROR getting data from db');
}
foreach ($shortnames as $shortname) { foreach ($shortnames as $shortname)
$count = 0; {
foreach ($r as $result) { $count = 0;
if(strpos($result['server'], "$shortname.") !== FALSE) {
$count = $result['count']; foreach ($r as $result)
break; {
} if (strpos($result['server'], "$shortname.") !== FALSE)
} {
echo "queuelength_${shortname}.value $count\n"; $count = $result['count'];
break;
}
}
echo "queuelength_${shortname}.value $count\n";
} }

View File

@ -28,65 +28,76 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set_include_path(get_include_path() . PATH_SEPARATOR . set_include_path(get_include_path() . PATH_SEPARATOR . "/etc/yubico/val:/usr/share/yubikey-val");
"/etc/yubico/val:/usr/share/yubikey-val");
require_once 'ykval-config.php'; require_once 'ykval-config.php';
function url2shortname ($url) { function url2shortname ($url)
if (preg_match("/^[^\/]+\/\/([a-z0-9-]+)/", $url, $name)==0){ {
echo "Cannot match URL hostname: " . $url . "\n"; if (preg_match("/^[^\/]+\/\/([a-z0-9-]+)/", $url, $name) == 0)
exit (1); {
} echo "Cannot match URL hostname: " . $url . "\n";
exit(1);
}
return $name[1]; return $name[1];
} }
$urls = $baseParams['__YKVAL_SYNC_POOL__']; $urls = $baseParams['__YKVAL_SYNC_POOL__'];
$shortnames = array_map("url2shortname", $urls); $shortnames = array_map("url2shortname", $urls);
if ($argc==2 && strcmp($argv[1], "autoconf") == 0) { if ($argc == 2 && strcmp($argv[1], "autoconf") == 0)
print "yes\n"; {
exit (0); print "yes\n";
exit (0);
} }
if ($argc==2 && strcmp($argv[1], "config") == 0) { if ($argc == 2 && strcmp($argv[1], "config") == 0)
{
echo "multigraph ykval_vallatency\n";
echo "graph_title VAL latency\n";
echo "graph_vlabel Average VAL Latency (seconds)\n";
echo "graph_category ykval\n";
echo "graph_width 400\n";
echo "multigraph ykval_vallatency\n"; foreach ($shortnames as $shortname)
echo "graph_title VAL latency\n"; {
echo "graph_vlabel Average VAL Latency (seconds)\n"; echo "ipv4${shortname}_avgwait.label IPv4-${shortname}\n";
echo "graph_category ykval\n"; echo "ipv4${shortname}_avgwait.type GAUGE\n";
echo "graph_width 400\n"; echo "ipv4${shortname}_avgwait.info Average VAL round-trip latency\n";
echo "ipv4${shortname}_avgwait.min 0\n";
echo "ipv4${shortname}_avgwait.draw LINE1\n";
foreach ($shortnames as $shortname) { echo "ipv6${shortname}_avgwait.label IPv6-${shortname}\n";
echo "ipv4${shortname}_avgwait.label IPv4-${shortname}\n"; echo "ipv6${shortname}_avgwait.type GAUGE\n";
echo "ipv4${shortname}_avgwait.type GAUGE\n"; echo "ipv6${shortname}_avgwait.info Average VAL round-trip latency\n";
echo "ipv4${shortname}_avgwait.info Average VAL round-trip latency\n"; echo "ipv6${shortname}_avgwait.min 0\n";
echo "ipv4${shortname}_avgwait.min 0\n"; echo "ipv6${shortname}_avgwait.draw LINE1\n";
echo "ipv4${shortname}_avgwait.draw LINE1\n"; }
echo "ipv6${shortname}_avgwait.label IPv6-${shortname}\n"; exit(0);
echo "ipv6${shortname}_avgwait.type GAUGE\n";
echo "ipv6${shortname}_avgwait.info Average VAL round-trip latency\n";
echo "ipv6${shortname}_avgwait.min 0\n";
echo "ipv6${shortname}_avgwait.draw LINE1\n";
}
exit (0);
} }
echo "multigraph ykval_vallatency\n"; echo "multigraph ykval_vallatency\n";
foreach ($urls as $url) { foreach ($urls as $url)
$shortname = url2shortname ($url); {
$cmd = "--user-agent ykval-munin-vallatency/1.0 --silent --write-out '%{time_total}' --max-time 3 '$url' -o /dev/null"; $shortname = url2shortname($url);
foreach (array('ipv4', 'ipv6') as $ipv) { $cmd = "--user-agent ykval-munin-vallatency/1.0 --silent --write-out '%{time_total}' --max-time 3 '$url' -o /dev/null";
$time = `curl --$ipv $cmd`;
if (preg_match("/^3\./", $time)) { foreach (array('ipv4', 'ipv6') as $ipv)
$time = "timeout"; {
} $time = `curl --$ipv $cmd`;
if (preg_match("/^0\.000/", $time)) {
$time = "error"; if (preg_match("/^3\./", $time))
} {
echo "$ipv${shortname}_avgwait.value $time\n"; $time = "timeout";
} }
if (preg_match("/^0\.000/", $time))
{
$time = "error";
}
echo "$ipv${shortname}_avgwait.value $time\n";
}
} }

View File

@ -28,73 +28,69 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
set_include_path(get_include_path() . PATH_SEPARATOR . set_include_path(get_include_path() . PATH_SEPARATOR . "/etc/yubico/val:/usr/share/yubikey-val");
"/etc/yubico/val:/usr/share/yubikey-val");
require_once 'ykval-config.php'; require_once 'ykval-config.php';
require_once 'ykval-db.php'; require_once 'ykval-db.php';
if ($argc==2 && strcmp($argv[1], "autoconf") == 0) { if ($argc == 2 && strcmp($argv[1], "autoconf") == 0)
print "yes\n"; {
exit (0); print "yes\n";
exit(0);
} }
if ($argc==2 && strcmp($argv[1], "config") == 0) { if ($argc == 2 && strcmp($argv[1], "config") == 0)
{
echo "graph_title YK-VAL YubiKey stats\n";
echo "graph_vlabel Known YubiKeys\n";
echo "graph_category ykval\n";
echo "graph_title YK-VAL YubiKey stats\n"; echo "yubikeys_enabled.label Enabled YubiKeys\n";
echo "graph_vlabel Known YubiKeys\n"; echo "yubikeys_enabled.draw AREA\n";
echo "graph_category ykval\n";
echo "yubikeys_enabled.label Enabled YubiKeys\n"; echo "yubikeys_disabled.label Disabled YubiKeys\n";
echo "yubikeys_enabled.draw AREA\n"; echo "yubikeys_disabled.draw STACK\n";
echo "yubikeys_disabled.label Disabled YubiKeys\n"; echo "yubikeys_1month.label YubiKeys seen last month\n";
echo "yubikeys_disabled.draw STACK\n"; echo "yubikeys_1month.draw LINE2\n";
echo "yubikeys_1month.label YubiKeys seen last month\n"; echo "clients_enabled.label Enabled validation clients\n";
echo "yubikeys_1month.draw LINE2\n"; echo "clients_enabled.draw LINE2\n";
echo "clients_enabled.label Enabled validation clients\n"; echo "clients_disabled.label Disabled validation clients\n";
echo "clients_enabled.draw LINE2\n"; echo "clients_disabled.draw LINE2\n";
echo "clients_disabled.label Disabled validation clients\n"; exit(0);
echo "clients_disabled.draw LINE2\n";
exit (0);
} }
# Connect to db
$db = Db::GetDatabaseHandle($baseParams, 'ykval-munin-yubikeystats'); $db = Db::GetDatabaseHandle($baseParams, 'ykval-munin-yubikeystats');
if (!$db->connect()) { if (!$db->connect())
logdie($myLog, 'ERROR Database connect error (1)'); logdie($myLog, 'ERROR Database connect error (1)');
function get_count($db, $table, $conditions)
{
$res = $db->customQuery('SELECT count(1) as count FROM ' . $table . ' WHERE ' . $conditions);
if ($res)
{
$r = $res->fetch(PDO::FETCH_ASSOC);
return $r['count'];
}
return Null;
} }
function get_count($db, $table, $conditions) { if ($count = get_count($db, 'yubikeys', 'active=true'))
$res = $db->customQuery('SELECT count(1) as count FROM ' . $table . ' WHERE ' . $conditions); echo "yubikeys_enabled.value " . $count . "\n";
if ($res) {
$r = $res->fetch(PDO::FETCH_ASSOC);
return $r['count'];
}
return Null; if ($count = get_count($db, 'yubikeys', 'active=false'))
} echo "yubikeys_disabled.value " . $count . "\n";
if ($count = get_count($db, 'yubikeys', 'active=true')) { if ($count = get_count($db, 'yubikeys', 'modified >= ' . (time() - (31 * 86400))))
echo "yubikeys_enabled.value " . $count . "\n"; echo "yubikeys_1month.value " . $count . "\n";
}
if ($count = get_count($db, 'yubikeys', 'active=false')) { if ($count = get_count($db, 'clients', 'active=true'))
echo "yubikeys_disabled.value " . $count . "\n"; echo "clients_enabled.value " . $count . "\n";
}
if ($count = get_count($db, 'yubikeys', 'modified >= ' . (time() - (31 * 86400)))) { if ($count = get_count($db, 'clients', 'active=false'))
echo "yubikeys_1month.value " . $count . "\n"; echo "clients_disabled.value " . $count . "\n";
}
if ($count = get_count($db, 'clients', 'active=true')) {
echo "clients_enabled.value " . $count . "\n";
}
if ($count = get_count($db, 'clients', 'active=false')) {
echo "clients_disabled.value " . $count . "\n";
}