CPM - Complete module to work with MyPrinterCloud System
use CPM; my $env=CPM->new(); $env->auto(-verbose=>1);
The CPM module manages the API of MyPrinterCloud, providing the subroutines to collect the information from the networked printers and to transmit it to CPS (Cloud Printing Server). It offers several options to accomplish key design criteria such as non-invasive, open, flexible, standard and scalable.
The CPM functionality is completely defined by its configuration file (config.xml) that acts also, as firmware of the module.
The CPM needs a default configuration file that must be adjusted by the user, at least, including his credentials (valid user in MyPrinterCloud).
<?xml version="1.0" encoding="UTF-8"?> <opt call="http://myprintercloud.nubeprint.com/np/selector.pl" proxy="" > <id comm="call" date="2010-09-10" mode="discover" pass="xxx" type="soft-public" user="firstname.lastname@example.org" /> <range from="105" to="115" lan=""/> </opt>
Communication with the CPS accepts two different forms depending on the needs of the destination network. Also, note that although there are two mechanisms you can activate only one per CPM.
This method is based on the HTTP standard, which operates in real time and is bidirectional. That allows the CPM apply the latest set of OIDs to be queried for a particular machine. Although an HTTP connection is needed, it is a very efficient solution.
This method is based on the SMTP standard with Auth support. When it's activated, the CPM collects all the information from the networked printers, composes a summary email, and sends it to the CPS. Obviously it is not bidirectional, nor in real-time, but in some cases this solution provides the Administrator an easier way to check or audit the information being transmitted.
<mail pass="yyy" smtp="myprintercloud.com" user="email@example.com"/>
If this method is enabled, the CPM discovers all the networked printers and for each one, it will request information to the CPS (if it's already registered, its model, the set of OIDs, ...). The CPM auto-detects the local net in order to make a scanning of the LAN.
The default discover behaviour can be modified specifying the local range and the subnet in where the CPM should scan. By default the CPM assumes the local net and from 1 to 254.
<range from="105" to="110" lan="192.168.2.0"/>
In this case the CPM gets a list of printers (section devices, embedded into the config file) to read, and for each one, it has already all the information needed to make a successful request.
<devices> <device ip="192.168.2.108" number="0"> <oid name="C1">.184.108.40.206.220.127.116.11.18.104.22.168.22.214.171.124.0</oid> <oid name="C18">.126.96.36.199.188.8.131.52.184.108.40.206.220.127.116.11.0</oid> <oid name="C2">.18.104.22.168.22.214.171.124.126.96.36.199.1</oid> <oid name="C4">.188.8.131.52.184.108.40.206.220.127.116.11.1</oid> <oid name="C5">.18.104.22.168.22.214.171.124.126.96.36.199.1</oid> <oid name="C59">.188.8.131.52.184.108.40.206.220.127.116.11.2</oid> <oid name="C60">.18.104.22.168.22.214.171.124.126.96.36.199.2</oid> </device> <device ip="192.168.2.109" number="1"> <oid name="C1">.188.8.131.52.184.108.40.206.220.127.116.11.18.104.22.168.0</oid> <oid name="C18">.22.214.171.124.126.96.36.199.188.8.131.52.184.108.40.206.0</oid> <oid name="C2">.220.127.116.11.18.104.22.168.22.214.171.124.1</oid> <oid name="C4">.126.96.36.199.188.8.131.52.184.108.40.206.1</oid> <oid name="C5">.220.127.116.11.18.104.22.168.22.214.171.124.1</oid> <oid name="C59">.126.96.36.199.188.8.131.52.184.108.40.206.2</oid> <oid name="C60">.220.127.116.11.18.104.22.168.22.214.171.124.2</oid> </device> </devices>
use CPM; my $env=CPM->new();
The CPM exports several subroutines to allow the developer to choose the way to handle the different transactions.
Create the object to handle the readings and the data transaction
Complete the transaction using the directives from the configuration file
Read printers of a List provided by the configuration file and use the Call method to send the data
Read printers of a List provided by the configuration file and send the data by email
Discover the networked printers and use the Call method to send the data
Discover the networked printers and send the data by email
Save the configuration data into the xml file
Make an SNMP request to read any OID. If MAC, it converts the hex values into an string like AA:BB:CC:DD If SN, it checks that it's a valid string. Enough lenght, and not resetted. Always converts the hex to ASCII strings
Make an SNMP walk request to read a complete branch
Determinate if exists an actived printer using the IP. If yes, it returns its SN
Read the Generics. It uses the common OIDs to try to identify the printer model and collect the basic information.
Read the specific model of printer. This function receives information from the CPS (OIDs of the model) and performs a specific SNMP request.
Juan Jose 'Peco' San Martin,
<peco at cpan.org>
Copyright 2010 NubePrint
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.