From nobody Sun Jul 24 15:21:23 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4LrRhz6ymbz4WpJw; Sun, 24 Jul 2022 15:21:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LrRhz6KF9z44sv; Sun, 24 Jul 2022 15:21:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658676083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YCYovejXADTGXMtMbUOVmFA2TwEX+xJhgb6plChf+IM=; b=IIyIZ2+kFZAgUB4IGnIIZwqDxWJ0QGYpCvfqqS+Z/Qvwkknpb8x1wdtv3ddeGN9hn2JrrI 3S6uqNXcv0dIhKPG51u7DWIaU9mum2Hh2zWCDA8dYFL0auqWyZTQO3rzYhicbN3qiA/WvF u0bqLAoyoaX6XAPvD4KWIl2VMoHDPVIdM5va12Jb+83bToYqaRCmOR9ulbTGFr0O/vsN+D NmaQ/fJnmGGPcjH3KGanBxGJI3ya5S6RNJ5VhEV6aaOz2JcXsZbcFEm21fk4WfnKgI7Oev Kjv2n5kNm0e7L3VDXtw/9Q6Ma/xcc/a+EzcS/auwU3SXxxnTeBZ3M7q4NrwzMg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4LrRhz5MlpzNYS; Sun, 24 Jul 2022 15:21:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 26OFLNEG089484; Sun, 24 Jul 2022 15:21:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26OFLNRb089483; Sun, 24 Jul 2022 15:21:23 GMT (envelope-from git) Date: Sun, 24 Jul 2022 15:21:23 GMT Message-Id: <202207241521.26OFLNRb089483@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alan Somers Subject: git: 982f980b86d6 - main - prometheus_sysctl_exporter: ignore ENOENT for mibs specified on the CLI List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: asomers X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 982f980b86d6bab4d55452d17bf3f5eb04e5f01e Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658676083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=YCYovejXADTGXMtMbUOVmFA2TwEX+xJhgb6plChf+IM=; b=P0Z+EcgY3YfiueSNQc4U6Uz+gZh/bankpBj3reXy73QamjYJx2Q5m2rRTcZQpL3brzBtNy 87uxfmL178GHVPkOGphCAifedNd4spMNZ50eSKARGIz3dV4W1zExZbFeX9KsMzTU6d6LaA ZVPLarBAk1iQvAaUKOPWPNj1B32uo1N1PAt2mmjqiE8dhRQCoI98K8kfbNEPpQ54XKwe0c WWbvzNq2XeGuIzrW1jnjD926eOUwqzm76C2sXI/2eQXDTnRSyTyG9hXwUrCjCpmcFaSMuq zdmnDI6BnvoVdALdHLQPGG/5vianLOM5uay2o3N1/026/P40vpYttNiIhm2iaA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1658676083; a=rsa-sha256; cv=none; b=m/JPutlsWPQswLW5FRBW+/463jXhOLDj1eFHi/Indnkmq6E2Lm7VeExKRql8O3e4eXYaAx 1ulOaqjgjwb5vEcMtJOQ6dTw9UyqyvTvwbDLNxkrXSEF5ukF0Kv3Z5LuvGwfey9+iLuSOq 4Fh8de5IgBaGO7SRW8pEMrKCNCP0+2OeA6xhmXJdMa1gLAe9si5ugRFELkf19wPSt5Fm9f TPkuQIDOxGXXl1TOEqMmPC8BdmrFU0KPcjeb2UNho8JiJhqx02PTu10jvUSS0h9WdvZWpL bG0RNRL9VWtqlDE0jIb1D+4McH4f1E+KVf5yBx5207JJh9ImZaeAnDb4REyUhA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=982f980b86d6bab4d55452d17bf3f5eb04e5f01e commit 982f980b86d6bab4d55452d17bf3f5eb04e5f01e Author: Alan Somers AuthorDate: 2022-06-21 18:51:14 +0000 Commit: Alan Somers CommitDate: 2022-07-24 15:19:46 +0000 prometheus_sysctl_exporter: ignore ENOENT for mibs specified on the CLI They might belong to kernel modules not currently loaded, or to other kernel versions. Ignoring them allows the configuration to be shared between multiple hosts. MFC after: 2 weeks Sponsored by: Axcient Reviewed by: rew Differential Revision: https://reviews.freebsd.org/D35540 --- .../prometheus_sysctl_exporter.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c b/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c index e452e305d2bf..931d8e965d00 100644 --- a/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c +++ b/usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c @@ -67,13 +67,12 @@ oid_get_root(struct oid *o) } /* Obtains the OID for a sysctl by name. */ -static void +static bool oid_get_by_name(struct oid *o, const char *name) { o->len = nitems(o->id); - if (sysctlnametomib(name, o->id, &o->len) != 0) - err(1, "sysctl(%s)", name); + return (sysctlnametomib(name, o->id, &o->len) == 0); } /* Returns whether an OID is placed below another OID. */ @@ -644,7 +643,15 @@ main(int argc, char *argv[]) for (i = 0; i < argc; ++i) { struct oid o, root; - oid_get_by_name(&root, argv[i]); + if (!oid_get_by_name(&root, argv[i])) { + /* + * Ignore trees provided as arguments that + * can't be found. They might belong, for + * example, to kernel modules not currently + * loaded. + */ + continue; + } o = root; do { oid_print(&o, &on, print_descriptions, exclude, include, fp);