diff --git a/ykval-munin-ksmlatency.php b/ykval-munin-ksmlatency.php index 27c3773..ef232b4 100755 --- a/ykval-munin-ksmlatency.php +++ b/ykval-munin-ksmlatency.php @@ -28,56 +28,65 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -set_include_path(get_include_path() . PATH_SEPARATOR . - "/etc/yubico/val:/usr/share/yubikey-val"); +set_include_path(get_include_path() . PATH_SEPARATOR . "/etc/yubico/val:/usr/share/yubikey-val"); require_once 'ykval-config.php'; -function url2shortname ($url) { - if (preg_match("/^[^\/]+\/\/([a-z0-9-]+)/", $url, $name)==0){ - echo "Cannot match URL hostname: " . $url . "\n"; - exit (1); - } +function url2shortname ($url) +{ + if (preg_match("/^[^\/]+\/\/([a-z0-9-]+)/", $url, $name) == 0) + { + echo "Cannot match URL hostname: " . $url . "\n"; + exit(1); + } - return $name[1]; + return $name[1]; } $ksms = otp2ksmurls ("ccccccccfnkjtvvijktfrvvginedlbvudjhjnggndtck", 16); $shortksms = array_map("url2shortname", $ksms); -if ($argc==2 && strcmp($argv[1], "autoconf") == 0) { - print "yes\n"; - exit (0); +if ($argc == 2 && strcmp($argv[1], "autoconf") == 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"; - 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"; + foreach ($shortksms as $shortksm) + { + 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"; + } - foreach ($shortksms as $shortksm) { - 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); + exit(0); } echo "multigraph ykval_ksmlatency\n"; -foreach ($ksms as $ksm) { - $shortksm = url2shortname ($ksm); - $time = `curl --silent --write-out '%{time_total}' --max-time 3 '$ksm' -o /dev/null`; - if (preg_match("/^3\./", $time)) { - $time = "timeout"; - } - if (preg_match("/^0\.000/", $time)) { - $time = "error"; - } - echo "${shortksm}_avgwait.value $time\n"; +foreach ($ksms as $ksm) +{ + $shortksm = url2shortname ($ksm); + $time = `curl --silent --write-out '%{time_total}' --max-time 3 '$ksm' -o /dev/null`; + + if (preg_match("/^3\./", $time)) + { + $time = "timeout"; + } + + if (preg_match("/^0\.000/", $time)) + { + $time = "error"; + } + + echo "${shortksm}_avgwait.value $time\n"; } diff --git a/ykval-munin-queuelength.php b/ykval-munin-queuelength.php index 9912a37..7a70579 100755 --- a/ykval-munin-queuelength.php +++ b/ykval-munin-queuelength.php @@ -28,63 +28,69 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -set_include_path(get_include_path() . PATH_SEPARATOR . - "/etc/yubico/val:/usr/share/yubikey-val"); +set_include_path(get_include_path() . PATH_SEPARATOR . "/etc/yubico/val:/usr/share/yubikey-val"); require_once 'ykval-config.php'; require_once 'ykval-db.php'; -function url2shortname ($url) { - if (preg_match("/^[^\/]+\/\/([a-z0-9-]+)/", $url, $name)==0){ - echo "Cannot match URL hostname: " . $url . "\n"; - exit (1); - } - return $name[1]; +function url2shortname ($url) +{ + if (preg_match("/^[^\/]+\/\/([a-z0-9-]+)/", $url, $name)==0) + { + echo "Cannot match URL hostname: " . $url . "\n"; + exit(1); + } + + return $name[1]; } -if ($argc==2 && strcmp($argv[1], "autoconf") == 0) { +if ($argc == 2 && strcmp($argv[1], "autoconf") == 0) +{ print "yes\n"; - exit (0); + exit(0); } $urls = $baseParams['__YKVAL_SYNC_POOL__']; $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"; - echo "graph_vlabel sync requests in queue\n"; - echo "graph_category ykval\n"; + foreach ($shortnames as $shortname) + { + echo "queuelength_${shortname}.label sync ${shortname}\n"; + echo "queuelength_${shortname}.draw AREASTACK\n"; + echo "queuelength_${shortname}.type GAUGE\n"; + } - foreach ($shortnames as $shortname) { - echo "queuelength_${shortname}.label sync ${shortname}\n"; - echo "queuelength_${shortname}.draw AREASTACK\n"; - echo "queuelength_${shortname}.type GAUGE\n"; - } - - exit (0); + exit(0); } - $db = Db::GetDatabaseHandle($baseParams, 'ykval-munin-queuelength'); -if (!$db->connect()) { - logdie($myLog, 'ERROR Database connect error (1)'); -} +if (!$db->connect()) + logdie($myLog, 'ERROR Database connect error (1)'); $res = $db->customQuery('select server,count(server) as count from queue group by server'); -if ($res) { - $r = $res->fetchAll(PDO::FETCH_ASSOC); -} else { - logdie($myLog, 'ERROR getting data from db'); -} +if ($res) + $r = $res->fetchAll(PDO::FETCH_ASSOC); +else + logdie($myLog, 'ERROR getting data from db'); -foreach ($shortnames as $shortname) { - $count = 0; - foreach ($r as $result) { - if(strpos($result['server'], "$shortname.") !== FALSE) { - $count = $result['count']; - break; - } - } - echo "queuelength_${shortname}.value $count\n"; +foreach ($shortnames as $shortname) +{ + $count = 0; + + foreach ($r as $result) + { + if (strpos($result['server'], "$shortname.") !== FALSE) + { + $count = $result['count']; + break; + } + } + + echo "queuelength_${shortname}.value $count\n"; } diff --git a/ykval-munin-vallatency.php b/ykval-munin-vallatency.php index a81bb5c..518ef52 100755 --- a/ykval-munin-vallatency.php +++ b/ykval-munin-vallatency.php @@ -28,65 +28,76 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -set_include_path(get_include_path() . PATH_SEPARATOR . - "/etc/yubico/val:/usr/share/yubikey-val"); +set_include_path(get_include_path() . PATH_SEPARATOR . "/etc/yubico/val:/usr/share/yubikey-val"); require_once 'ykval-config.php'; -function url2shortname ($url) { - if (preg_match("/^[^\/]+\/\/([a-z0-9-]+)/", $url, $name)==0){ - echo "Cannot match URL hostname: " . $url . "\n"; - exit (1); - } +function url2shortname ($url) +{ + if (preg_match("/^[^\/]+\/\/([a-z0-9-]+)/", $url, $name) == 0) + { + echo "Cannot match URL hostname: " . $url . "\n"; + exit(1); + } - return $name[1]; + return $name[1]; } $urls = $baseParams['__YKVAL_SYNC_POOL__']; $shortnames = array_map("url2shortname", $urls); -if ($argc==2 && strcmp($argv[1], "autoconf") == 0) { - print "yes\n"; - exit (0); +if ($argc == 2 && strcmp($argv[1], "autoconf") == 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"; - echo "graph_title VAL latency\n"; - echo "graph_vlabel Average VAL Latency (seconds)\n"; - echo "graph_category ykval\n"; - echo "graph_width 400\n"; + foreach ($shortnames as $shortname) + { + echo "ipv4${shortname}_avgwait.label IPv4-${shortname}\n"; + echo "ipv4${shortname}_avgwait.type GAUGE\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 "ipv4${shortname}_avgwait.label IPv4-${shortname}\n"; - echo "ipv4${shortname}_avgwait.type GAUGE\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"; + echo "ipv6${shortname}_avgwait.label IPv6-${shortname}\n"; + 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"; + } - echo "ipv6${shortname}_avgwait.label IPv6-${shortname}\n"; - 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); + exit(0); } echo "multigraph ykval_vallatency\n"; -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"; - foreach (array('ipv4', 'ipv6') as $ipv) { - $time = `curl --$ipv $cmd`; - if (preg_match("/^3\./", $time)) { - $time = "timeout"; - } - if (preg_match("/^0\.000/", $time)) { - $time = "error"; - } - echo "$ipv${shortname}_avgwait.value $time\n"; - } +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"; + + foreach (array('ipv4', 'ipv6') as $ipv) + { + $time = `curl --$ipv $cmd`; + + if (preg_match("/^3\./", $time)) + { + $time = "timeout"; + } + + if (preg_match("/^0\.000/", $time)) + { + $time = "error"; + } + + echo "$ipv${shortname}_avgwait.value $time\n"; + } } diff --git a/ykval-munin-yubikeystats.php b/ykval-munin-yubikeystats.php index 19024bf..e3c4407 100755 --- a/ykval-munin-yubikeystats.php +++ b/ykval-munin-yubikeystats.php @@ -28,73 +28,69 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -set_include_path(get_include_path() . PATH_SEPARATOR . - "/etc/yubico/val:/usr/share/yubikey-val"); +set_include_path(get_include_path() . PATH_SEPARATOR . "/etc/yubico/val:/usr/share/yubikey-val"); require_once 'ykval-config.php'; require_once 'ykval-db.php'; -if ($argc==2 && strcmp($argv[1], "autoconf") == 0) { - print "yes\n"; - exit (0); +if ($argc == 2 && strcmp($argv[1], "autoconf") == 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 "graph_vlabel Known YubiKeys\n"; - echo "graph_category ykval\n"; + echo "yubikeys_enabled.label Enabled YubiKeys\n"; + echo "yubikeys_enabled.draw AREA\n"; - echo "yubikeys_enabled.label Enabled YubiKeys\n"; - echo "yubikeys_enabled.draw AREA\n"; + echo "yubikeys_disabled.label Disabled YubiKeys\n"; + echo "yubikeys_disabled.draw STACK\n"; - echo "yubikeys_disabled.label Disabled YubiKeys\n"; - echo "yubikeys_disabled.draw STACK\n"; + echo "yubikeys_1month.label YubiKeys seen last month\n"; + echo "yubikeys_1month.draw LINE2\n"; - echo "yubikeys_1month.label YubiKeys seen last month\n"; - echo "yubikeys_1month.draw LINE2\n"; + echo "clients_enabled.label Enabled validation clients\n"; + echo "clients_enabled.draw LINE2\n"; - echo "clients_enabled.label Enabled validation clients\n"; - echo "clients_enabled.draw LINE2\n"; + echo "clients_disabled.label Disabled validation clients\n"; + echo "clients_disabled.draw LINE2\n"; - echo "clients_disabled.label Disabled validation clients\n"; - echo "clients_disabled.draw LINE2\n"; - - exit (0); + exit(0); } -# Connect to db $db = Db::GetDatabaseHandle($baseParams, 'ykval-munin-yubikeystats'); -if (!$db->connect()) { - logdie($myLog, 'ERROR Database connect error (1)'); +if (!$db->connect()) + 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) { - $res = $db->customQuery('SELECT count(1) as count FROM ' . $table . ' WHERE ' . $conditions); - if ($res) { - $r = $res->fetch(PDO::FETCH_ASSOC); - return $r['count']; - } +if ($count = get_count($db, 'yubikeys', 'active=true')) + echo "yubikeys_enabled.value " . $count . "\n"; - return Null; -} +if ($count = get_count($db, 'yubikeys', 'active=false')) + echo "yubikeys_disabled.value " . $count . "\n"; -if ($count = get_count($db, 'yubikeys', 'active=true')) { - echo "yubikeys_enabled.value " . $count . "\n"; -} +if ($count = get_count($db, 'yubikeys', 'modified >= ' . (time() - (31 * 86400)))) + echo "yubikeys_1month.value " . $count . "\n"; -if ($count = get_count($db, 'yubikeys', 'active=false')) { - echo "yubikeys_disabled.value " . $count . "\n"; -} +if ($count = get_count($db, 'clients', 'active=true')) + echo "clients_enabled.value " . $count . "\n"; -if ($count = get_count($db, 'yubikeys', 'modified >= ' . (time() - (31 * 86400)))) { - echo "yubikeys_1month.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"; -} +if ($count = get_count($db, 'clients', 'active=false')) + echo "clients_disabled.value " . $count . "\n";