1

I am setting up an icinga server for monitoring printer status via SNMP (toner levels, errors, that kind of thing). All of the printers are accessible via a shared windows print server (Printer is added to client machines via \SERVER\Printer_Share). While I am able to query the printers by IP directly via SNMP that tells me nothing about what their name. Is it possible to query the Windows print server from Linux to produce an output similar to:

Shared Printer 1 -> IP_1
Shared Printer 2 -> IP_2
Shared Printer 3 -> IP_3
Shared Printer 4 -> IP_4

With this info I can then write a script to create icinga config files. There are hundreds of printers so I am not doing this manually. I'm not asking anyone to write a script for me but rather point me in the right direction.

  • Any reason you don't register the printer IPs in DNS? – jscott Apr 15 '14 at 12:39
  • We don't handle that – windowslinux Apr 15 '14 at 12:41
3

Your options:

1. evaluate registry data

  • query for the subkeys of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Printers to get a list of printers
  • match the port value against HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports
  • evaluate the HostName and IPAddress values within the matching key

2. use Powershell

  • similar to 1. but use Get-Printer and Get-PrinterPort cmdlets to do retreive the respective data via a well-defined interface (you would need to use a Windows 8.1 or Server 2012 hosts to run the CMDlets, but the print server you're running them against could be an older version)

3. use WMI

  • similar to 1. and 2., but use the WMI Win32_Printer class to retreive a list of printers and the Win32_TCPIPPrinterPort class to retreive the HostAddress value in your WMI-query-capable language of choice (e.g. VBScript)

Note that there is no uniform way to do this if your printers are using something vendor-specific instead of the Standard TCP/IP Port. You would need to go and figure it all out, although chances are that this information would be buried somehwere in the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\<yourporttype> registry subkey.

Note that while you theoretically could remote stuff from a Linux station using RPC, it probably would be a better idea to have NRPE transport the data (take a look at NSClient++ using external scripts)

  • Thanks. I got the output with VBS, put a text file in a share, and parsed it with Perl – windowslinux Apr 15 '14 at 15:58
  • @windowslinux this works too, of course. I mentioned NRPE since I understood that you wanted this information in Icinga. After giving your question a second read, It dawned on me that you just wanted to generate semi-static config files from this information. – the-wabbit Apr 16 '14 at 6:08

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.