Page 2 of 3 <123>
Topic Options
#210975 - 2015-12-14 12:43 PM Re: SNMP with Printers [Re: kelp7]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Main issue now seems to be that Split is not putting all the different keys into separate array elements. $aColors[0] contains all of the keys one after another delimited by CRLF
Top
#210976 - 2015-12-14 12:46 PM Re: SNMP with Printers [Re: kelp7]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Hey - don't be hangin' around spreading those germy bits 'n bytes!

Feel better!
_________________________
Actually I am a Rocket Scientist! \:D

Top
#210977 - 2015-12-14 12:51 PM Re: SNMP with Printers [Re: Glenn Barnas]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
\:\) Thanks!

I'm back at work today but still not shaken it all off.

Just trying to work out what's happening with ReadProfileString actually, I wonder whether the results it returns (when it returns all keys in the variable) are actually delimited by CRLF or by something else...

Top
#210978 - 2015-12-14 12:57 PM Re: SNMP with Printers [Re: kelp7]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
Look at the EnumIni UDF - either for ideas or use it as-is.. it does all the heavy lifting of reading the INI (just like you are) and assembling the array.

It is also forgiving about the vars you pass, in fact - it doesn't want them!
 Code:
$aSections = EnumIni($IniFile)  ; return an array of sections in the INI file

$aValues = EnumIni($IniFile, $Section) ; return an array of values within a section
Often, you'll use the first form and enumerate the list of sections, sometimes excluding certain sections such as "COMMON" or "SETTINGS" which contain app settings. The remaining sections might need to be enumerated to gather specific information, such as a file containing a collection of tasks to perform.

The second form returns the list of VALUES, but not any data. This generally is enumerated to perform the specific ReadProfileString($IniFile, $Section, $Value) to get the actual data.

Looking at the EnumIni code, it seems that the delimiter is newline ( Chr(10) ) and not @CRLF. Sorry about that!

FYI - the latest version of any of my UDFs is available from my web site - I have a Kix service that runs to sync my UDF lib with the web site, running PostPrep in the process. It also creates a Zip file of all the UDFs for quick access to everything.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#210979 - 2015-12-14 01:06 PM Re: SNMP with Printers [Re: Glenn Barnas]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Thanks Glenn, I always make sure to get any UDFs direct from your website to ensure I get the right versions. Interesting about the Newline character, I'll see if that works. I will check out the Enumini UDF though!
Top
#210980 - 2015-12-14 01:17 PM Re: SNMP with Printers [Re: kelp7]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Yeah that works now.

I had to put an IF $Color ENDIF section as it seemed to try to work on an empty array element at some point (at the end of the loop I think). But otherwise, all working fine so far, output as follows:

 Code:
C:\Scripts>kix32 printerquery.kix
Processing INI value: Model
Xerox Phaser 6600DN
Processing INI value: Location
SSD Dispatch
Processing INI value: Cyan
1600
Processing INI value: Magenta
1200
Processing INI value: Yellow
1200
Processing INI value: Black
1800


This is just for a specific printer so far, that'll be the next task (looping through a list of printers). Well, actually, the next task is taking those color values returned by the snmpget and dividing them appropriately by the maximum values to get the percentage left. Fun!


Edited by kelp7 (2015-12-14 01:18 PM)

Top
#210981 - 2015-12-14 02:22 PM Re: SNMP with Printers [Re: kelp7]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
 Originally Posted By: kelp7
OK But in the manual it suggests that if the parameter is empty then it'll return all the keys. Anyway, I've worked it out now, the script simply wasn't finding the file! I'm working on a new 2012 server and had forgotten to show all file extensions. So only now do I find out that my .ini file is actually called PrinterData.ini.txt (simple mistake but what a doofus). Right, on with the scripting!!


Sorry! I should read better. I have some difficulties "starting up" after just 4 hours of sleep and a very busy and sort off messed up weekend.

LOL those pesky .ini.txt files have bitten me also some time ago. A simple mistake but so easy to overlook.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#210982 - 2015-12-14 03:44 PM Re: SNMP with Printers [Re: Mart]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
 Originally Posted By: Mart
Sorry! I should read better. I have some difficulties "starting up" after just 4 hours of sleep and a very busy and sort off messed up weekend.

LOL those pesky .ini.txt files have bitten me also some time ago. A simple mistake but so easy to overlook.


Not a problem \:\) I'm just glad that I now have a nearly completely working script!

One thing I'm struggling with at the moment is that I need to convert some of the results (the toner levels) from strings to numerics and carry out some calculations on them. I'm carrying out a divide calculation but because I'm currently using CInt() to convert from string to number obviously I don't get the fractional part. Scratching my head about this one but I'm sure I'll crack it shortly...

Top
#210983 - 2015-12-14 03:46 PM Re: SNMP with Printers [Re: kelp7]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
(Perhaps 'VAL()' is my answer to this one...)
Top
#210984 - 2015-12-14 03:54 PM Re: SNMP with Printers [Re: kelp7]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
If you look at my second response you will see you do have to have both values as "" to get the sections. Even though the values are blank, the function requires something to be there or it will bark at you. \:\)
Top
#210985 - 2015-12-14 04:09 PM Re: SNMP with Printers [Re: Allen]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Argh, from the Kixtart manual:

"/ Used to divide two numbers and return an integer result."

Really do not want integers! Going to go straight to Glenn's website now and look through some UDFs!

Top
#210986 - 2015-12-14 04:43 PM Re: SNMP with Printers [Re: kelp7]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Even more interesting is that if I run a piece of code:

 Code:
$A = 4400.00
$B = 11000.00
$C = ($A / $B)


I do actually get a result that includes a decimal point and remainder! Not sure what the manual is talking about.

Still have the difficulty of not being able to convert a string to a number that's not an integer.


Edited by kelp7 (2015-12-14 04:44 PM)

Top
#210987 - 2015-12-14 05:02 PM Re: SNMP with Printers [Re: kelp7]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
Try
 Code:
cdbl($inivalue)

Top
#210988 - 2015-12-14 05:02 PM Re: SNMP with Printers [Re: Allen]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Interesting, okay thanks, I'll look that function up.
Top
#210989 - 2015-12-14 05:04 PM Re: SNMP with Printers [Re: kelp7]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Perfect \:\) Thanks for that, it works.
Top
#210990 - 2015-12-14 06:27 PM Re: SNMP with Printers [Re: kelp7]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
 Originally Posted By: kelp7
Really do not want integers! Going to go straight to Glenn's website now and look through some UDFs!
Have you looked at KGen and the Kix Development Kit on my site? It simplifies management of app development and deployment.

Operation is pretty simple:
Create a Dev folder, with a KixLib subfolder. Can be a network share.
Define a System environment var called KixLibPath and point to the Dev\KixLib folder.
Copy the KGen.bat file to a folder that's in your Path (C:\Windows is OK for testing).

Create a subfolder in Dev for your project, and create your basic script.txt file there. Don't include any public UDFs in your code.
Optionally, break your script into modules, with your app-specific UDFs placed in a script.udf file in the same folder. I often break large files into multiple .UDF files in the project folder.

When you run (from a command prompt) KGEN script (without the .txt extension) it will parse your code, include all local .KXF and .UDF files, and then recursively scan your script and the external UDFs to include any required files from the KixLib folder. It creates a .KIX file ready to run with all needed UDFs. It also runs your finished script through the Sanity UDF, which checks for variable definitions, mismatched operator pairs (if/endif) and paired character sets (quotes, parens, and such).

The package is free to download and use, and has way more options and capabilities than I've mentioned here. Refer to the User Guide for complete information.

Using one of the advanced options (build.ini), I can run KGEN to build a new rev and copy it to the app folder on my machine. After local testing and validation, I re-run KGEN with a "PROD" argument and it re-gens the script, tokenizes it, and copies it to the shared folder for deployment.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#210991 - 2015-12-15 11:13 AM Re: SNMP with Printers [Re: Glenn Barnas]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Hi Glenn,

That is awesome but I only do the very occasional bit of scripting, it's not a big part of what I do (hence my constant state of re-learning everything again and I only ever hang out in the Basic Scripting forum \:\) )

I'll take a look though just out of interest

Cheers
kelp

Top
#210992 - 2015-12-15 11:18 AM Re: SNMP with Printers [Re: kelp7]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
So, making good headway with the script today. I've decided to scrap the 'MODEL' part of the INI file and have now implemented a nifty bit of code that reads the model of the machine from the very first OID on the device. I've had to rename each section of the INI file to exactly match what comes back in the first OID on each device though.

Here's a couple of examples of what you get back from the first OID:

 Code:
.1.3.6.1.2.1.1.1.0,OctetString,Xerox Phaser 3320;Sys SW Version Phaser3320_V53.005.00.000 MAY-16-2014,MCB V2.50.04.00 MAY-16-2014,NIC V4.04.00,IOT V1.00.33,PCL5e 6.50.02.03,PCL6 6.23.00.02,PS 2.83.00.59.00.59 ,IBM/EPSON 5.29.01, IP Core 6.8.P


and

 Code:
.1.3.6.1.2.1.1.1.0,OctetString,Xerox WorkCentre 7835 v1 Multifunction System; System Software 071.010.103.04401, ESS 071.013.04411


for two different models. Just came up with this bit of code:

 Code:
$Cmd = 'snmpget.exe -r:' + $PrinterIP + ' -o:.1.3.6.1.2.1.1.1.0 -q'
$CmdResult = WshPipe($Cmd)
$CmdResult = Join($CmdResult[0], @CRLF)
$PModel = SubStr($CmdResult, Instr($CmdResult, "X"), (Instr($CmdResult, ";") - Instr($CmdResult, "X")))


which does the job nicely of populating the $PModel variable and that can then be used to find the right section of the INI (with the ReadProfileString function).

All looking great so far.

My only issue is that I am really going to have to create a data file containing a list of all the IPs of the printers we have and it'll cycle through this file querying each printer in turn. Bit annoying but I don't see any other way of doing it unless we change our system of not publishing printers in the directory.

Top
#210999 - 2015-12-16 04:56 PM Re: SNMP with Printers [Re: kelp7]
kelp7 Offline
Starting to like KiXtart

Registered: 2002-08-12
Posts: 124
Loc: UK
Script finished and operational running twice a day via windows task scheduler.

Thanks guys for all your input and help.

Top
#211001 - 2015-12-16 09:02 PM Re: SNMP with Printers [Re: kelp7]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11623
Loc: CA
Great. Can you post a final code solution you came up with?

Thanks

Top
Page 2 of 3 <123>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 259 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.105 seconds in which 0.046 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org