I have had to use this method in the past to access global variables.
···
-----Original Message-----
From: checkmk-en [mailto:checkmk-en-bounces@lists.mathias-kettner.de] On Behalf Of Lincoln Yellick
Sent: 06 November 2017 15:05
To: ‘Evy Bongers’; ‘checkmk-en@lists.mathias-kettner.de’
Subject: Re: [Check_mk (english)] Getting current hostname that check is running against
Thank you for the reply.
Yeah it seems like I’ll have to come up with a clever way to do this check. The g_hostname just comes back as unknown.
Is there a way to use the oid() function from the check_info in another function? That way I could just use that oid() function to get the hostname.
Thanks,
Lincoln Hach Yellick
Managed Service Technician
Blue Net, Inc.
1301 Corporate Center Drive, Suite 112
Eagan, MN 55121
P: 651-203-8817 S: 651-203-8850
lyellick@bluenetinc.com
-----Original Message-----
From: Evy Bongers [mailto:lists+check-mk@evybongers.nl]
Sent: Sunday, November 5, 2017 12:09 PM
To: Lincoln Yellick lyellick@bluenetinc.com; ‘checkmk-en@lists.mathias-kettner.de’ checkmk-en@lists.mathias-kettner.de
Subject: Re: [Check_mk (english)] Getting current hostname that check is running against
I don’t think there’s a documented list of global variables.
To find out which variables are available in the global scope, you can use the globals()[1,2] function.
To reference the variable, you can use if like any other variable, for
example:
print ( g_hostname )
svc_long_output += “Check ran on host %s” % g_hostname
Regards,
Evy
[1] https://docs.python.org/2/library/functions.html#globals
[2] https://docs.python.org/3/library/functions.html#globals
On 03/11/17 22:01, Lincoln Yellick wrote:
Thank you Evy!
How would one reference a global variable in their custom check and where is a list of these? We would love to know.
Lincoln Hach Yellick
Managed Service Technician
Blue Net, Inc.
1301 Corporate Center Drive, Suite 112 Eagan, MN 55121
P: 651-203-8817 S: 651-203-8850
lyellick@bluenetinc.com
-----Original Message-----
From: Evy Bongers [mailto:lists+check-mk@evybongers.nl]
Sent: Friday, November 3, 2017 3:52 PM
To: Lincoln Yellick lyellick@bluenetinc.com;
‘checkmk-en@lists.mathias-kettner.de’
checkmk-en@lists.mathias-kettner.de
Subject: Re: [Check_mk (english)] Getting current hostname that check
is running against
If I remember correctly, there’s a global variable g_hostname that you can use for this.
Regards,
Evy
On 03/11/17 19:36, Lincoln Yellick wrote:
Hello,
I am writing a custom check to show the status of phones in a cloud
PBX and need a way to be able to pass the current hostname that a
check is running against.
Here is the code I wrote to accomplish this:
Ideally I would like the function generate_sip_oids() to use the
hostname that this is running against. At the current state it really
just checks against one host when it should be any.
try:
import subprocess
import re
except ImportError:
pass
def generate_sip_oids():
collection = []
command = "snmpget -v 2c -c [key] [hostname] .1.3.6.1.4.1.22736.10.4.1"
number_of_sip_phones_cmd =
subprocess.check_output(command.split(),
shell=False)
number_of_sip_phones = re.search("(?<=INTEGER: ).*",
number_of_sip_phones_cmd)
for i in range(int(number_of_sip_phones.group(0))):
oid_string = ".1.3.6.1.4.1.22736.10.4.3." + str(i+1)
sip_oid = (oid_string, ["1", "2", "3", "4", "5", "6"])
collection.append(sip_oid)
return collection
def inventory_dev_digium_register_status(info):
return [("%s" % line[0][1], None) for line in info]
def check_dev_digium_register_status(item, _no_params, info):
# item is the current item being passed from the inventory
function
# info is the master array being passed
# looping through each item in info
for line in info:
# checking if the ext number is equal to the ext item
if line[0][1] == item:
# variables
user = str(line[0][2])
ext = str(line[0][1])
ip = str(line[0][4])
status = str(line[0][5])
if status == "unreachable":
return 2, "Down - User: {0}, Ext.: {1}, IP:
{2}".format(user, ext, ip)
elif status == "registered":
return 0, "Is Ok - User: {0}, Ext.: {1}, IP:
{2}".format(user, ext, ip)
else:
return 3, "State Unknown"
check_info[“dev_digium_register_status”] = {
"check_function": check_dev_digium_register_status,
"inventory_function": inventory_dev_digium_register_status,
"service_description": "Digium Phone: Ext. %s", # index title
"snmp_info": generate_sip_oids(),
"snmp_scan_function": lambda oid:
oid(“.1.3.6.1.4.1.22736.10.1.1”) is not None }
cid:image002.png@01D27D56.7156D060
Lincoln Hach Yellick
Managed Service Technician
--------------------------------------------
Blue Net, Inc.
1301 Corporate Center Drive, Suite 112 Eagan, MN 55121
*P:*651-203-8817 *S: *651-203-8850
lyellick@bluenetinc.com mailto:lyellick@bluenetinc.com
checkmk-en mailing list
checkmk-en@lists.mathias-kettner.de
http://lists.mathias-kettner.de/mailman/listinfo/checkmk-en
kettner.de
checkmk-en mailing list
checkmk-en@lists.mathias-kettner.de
http://lists.mathias-kettner.de/mailman/listinfo/checkmk-en
This email has been sent by a member of the Man group (“Man”). Man’s parent company, Man Group plc, is registered in England and Wales (company number 08172396) at Riverbank House, 2 Swan Lane, London, EC4R 3AD.
The contents of this email are for the named addressee(s) only. It contains information which may be confidential and privileged. If you are not the intended recipient, please notify the sender immediately, destroy this email and any attachments and do not otherwise disclose or use them. Email transmission is not a secure method of communication and Man cannot accept responsibility for the completeness or accuracy of this email or any attachments. Whilst Man makes every effort to keep its network free from viruses, it does not accept responsibility for any computer virus which might be transferred by way of this email or any attachments. This email does not constitute a request, offer, recommendation or solicitation of any kind to buy, subscribe, sell or redeem any investment instruments or to perform other such transactions of any kind. Man reserves the right to monitor, record and retain all electronic and telephone communications through its network in accordance with applicable laws and regulations.