pax_global_header 0000666 0000000 0000000 00000000064 14323200667 0014515 g ustar 00root root 0000000 0000000 52 comment=61f036e4ce5609efe901ec9e048339d3ee8d5b0e
UnixAgent-2.10.0/ 0000775 0000000 0000000 00000000000 14323200667 0013477 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/.github/ 0000775 0000000 0000000 00000000000 14323200667 0015037 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/.github/Contributing.md 0000664 0000000 0000000 00000012310 14323200667 0020025 0 ustar 00root root 0000000 0000000
OCS Inventory
Some Links:
Ask question |
Installation |
Website
# OCS Inventory Contributing Guidelines
## Pull Request Process
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Add your changes: `git add folder/file1.php`
4. Commit your changes: `git commit -m 'Add some feature'`
5. Push to the branch: `git push origin my-new-feature`
6. Submit a pull request !
## Pull Request Informations
When contributing, please open an issue before or contact the team using mail. This will prevent all the duplicate of work.
Also, check if your contribution is not already in the roadmap or affiliated to an issue.
If you are contributing on a small scale (translation, a few line modification), you don't need open an issue or contact the team but you will need to explain what you've done in the Pull Request comment and provide as accurate commit messages as possible.
Cf. Commits Messages Name Informations
If you need to discuss about a big change or need some help of our team during the development of your contribution,
we can use other communication method like Telegram, IRC, Skype.
## Commits Messages Name Informations
Try to create as accurate as possible commit messages.
This will help us to speed up the review process and to reduce the misunderstanding (which can lead to a Pull Request to be rejected)
There is no commit messages convention but here are some examples :
1. Create as short as possible commit name
2. One commit for one modification
3. Always leave the second commit line blank
If it seems difficult to summarize what your commit does, it may be because it includes several logical changes or bug fixes, and are better split up into several commits using `git add -p`.
## Code of Conduct
### Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.
### Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
### Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
### Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
### Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at `contact@ocsinventory-ng.org` . All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
### Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]
[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
UnixAgent-2.10.0/.github/ISSUE_TEMPLATE.md 0000664 0000000 0000000 00000000566 14323200667 0017553 0 ustar 00root root 0000000 0000000 *It's hard to solve a problem when important details are missing, that why we added this template, to help you and us.*
### General informations
Operating system :
Perl version :
### OCS Inventory informations
Unix agent version :
### Problem's description
*Describe your problem here*
### Inventory log file ( optional )
*Use github cloud or trusted upload website*
UnixAgent-2.10.0/.github/PULL_REQUEST_TEMPLATE.md 0000664 0000000 0000000 00000002030 14323200667 0020633 0 ustar 00root root 0000000 0000000 ## Must read before submitting
Please, take a look to our contributing guidelines before submitting your pull request.
There's some simple rules that will help us to speed up the review process and avoid any misunderstanding
[Contributors GuideLines](https://github.com/OCSInventory-NG/OCSInventory-ocsreports/blob/master/.github/Contributing.md)
## Status
**READY/IN DEVELOPMENT/HOLD**
## Description
A few sentences describing the overall goals of the pull request's commits.
## Related Issues
Put here all the related issues link
## Todos
- [ ] Tests
- [ ] Documentation
## Test environment
If some tests has been already made, please give us your test environment' specs
#### General informations
Operating system :
Perl version :
#### OCS Inventory informations
Unix agent version :
## Deploy Notes
Notes regarding deployment the contained body of work. These should note any dependencies changes,
logical changes, etc.
1.
## Impacted Areas in Application
List general components of the application that this PR will affect:
*
UnixAgent-2.10.0/.gitignore 0000664 0000000 0000000 00000000757 14323200667 0015500 0 ustar 00root root 0000000 0000000 # Mac OS Specific dir
.DS_Store
build/
*.old
# Iceberg specific dir
tools/macosx/installer_gui/iceberg/OCSNG.app/
tools/macosx/installer_gui/iceberg/ocscontact
tools/macosx/installer_gui/iceberg/plugins/
# Ignore darwin perl lib if un tar from script repository
tools/macosx/scripts/darwin-perl-lib/
# Xcworkspace and user data
project.xcworkspace/
xcuserdata/
# perl Makefile.PL
/MYMETA.json
/MYMETA.yml
/Makefile
/ipdiscover
/run-postinst
# make
/blib/
/pm_to_blib
# make dist
/*.tar.gz
UnixAgent-2.10.0/.travis.yml 0000664 0000000 0000000 00000000522 14323200667 0015607 0 ustar 00root root 0000000 0000000 language: perl
perl:
- "5.30"
- "5.28"
- "5.26"
- "5.20"
before_install:
- sudo apt -y install dmidecode make gcc
- cpanm --quiet --installdeps --notest .
script: env PERL_AUTOINSTALL=1 perl Makefile.PL && sudo make && sudo make install
addons:
apt:
update: true
branches:
only:
- master UnixAgent-2.10.0/AUTHORS 0000664 0000000 0000000 00000000660 14323200667 0014551 0 ustar 00root root 0000000 0000000 Maintainer:
Frank Bourdeau
Former maintainers:
Guillaume PROTET
Gonéri LE BOUDER
Based on the legacy OCS Linux agent (Copyright (C) 2005-2008 Pascal DANEK )
Copyright 2006-2020 OCS Inventory contributors
Website: http://www.ocsinventory-ng.org
Please read THANKS to get the list of the contributors
UnixAgent-2.10.0/Changes 0000664 0000000 0000000 00000152230 14323200667 0014775 0 ustar 00root root 0000000 0000000 Revision history for Ocsinventory::Agent
2.9.1
* Copy cronjob script from Fedora
* Permit storing CA list in config dir
* Don't check XML if in forced mode
* Prevent misunderstanding of version option from config file
* Remove forbidden char in XML
* Fix Agent 2.9.0 not reporting OS minor release on Debian
* Fix addInput missing keys
* Fix SNMP macadress format
2.9.0
* Adding new Screen Manufacturer
* Update OSRelease.pm
* Change product name for Lenovo systems
* Small improvements in the parse of config file options
* Checking if XML is valid before submitting
* Fix Unix user inventory
* Fix raspberry has no serial
* Fix timeout from last command
* Fix memory issue on MacOS
* Fix empty value for ip address when contains 127
* Fix IpDiscover compilation
* Fix lshw storage discovery fails on servers with one device
* Fix bug group members displaying as HASH
* Fix the bad management of the inventor in RHEL
* Fix gateway misbehaviour with multiple network interfaces
* Fix XML has not well formed
* Fix issue Ubuntu 21.10 being reported as Ubuntu 11.0
* Remove devtmpfs partition inventory
2.8.1
* Add octectstring management on SNMP Scan
* Add retry and timeout config for SNMP
* Fix perl warnings on HASH
* Fix warning on SNMP Scanner
* Fix digit retrival using bigger digit and avoid truncate
* Remove old SNMP scanning feature
2.8
* Rework SNMP Interface and configuration
* Rework IPDiscover manager
* Rework LDAP Authenticaiton
* Rework Auth backend
* Rework software inventory data structure
* Add MySQL 8 compatibility
* Add ASCII code management on deployment messages
* Add "is not empty" criteria on multi search
* Add computer archive feature
* Add IPDiscover scan split by TAG
* Add CVE Matching regex
* Add chinese translation
* Add perl injector related inventory on main dashboard
* Update German translation
* Improve CVE Inventory
* Improve translation on deployment form
* Move networks submenu to inventory menu for better visibility
* Fix date interval search on multi criteria
* Fix IPDiscover subnet blacklist
* Fix CVE-2020-14947
* Fix stats to match user TAG restrictions
* Fix CSV export to match table show / hide configuration
* Fix minor bugs on CVE Inventory
* Fix deployment estimation time when editing a packaged
* Fix deployment fragment bug
* Fix small package deployment (< 1024 bytes)
* Fix a bug on MySQL SSL connection
* Remove SNMP_INVENTORY_DIFF
* Typos fix
* Minor bug fix
2.6.1
* Allow encode http password in base64
* Fix repository inventory #254
* MacOS installer / packaging rework
* Suppress error message for LSPCI
* Fix oracle package setup
* Remove uninitialized value message
* Now use os-release file
* Improve drives management (Linux / MacOS)
* Imprive IPv6 inventory
2.6.0
* Fix issue Service-Pack wrong info on Linux Clients (reports on https://github.com/OCSInventory-NG/OCSInventory-ocsreports/issues/741)
* Fix issues #181, #187, #194, #197
* Merge PR #175, #178, #190, #191, #193, #196, #199, #201
2.4.2
* Fix warning argument freebsd isn't numeric
* Fix Debian repository
* Update manifest
* Fix name and url in Repository
* Fix for Ubuntu and older Debian version
* Merge PR #141,#135,#143
* Fix spelling errors
* Add arcconf for Adaptec
* Fix issue #124
* Replace hpacucli with ssacli
* Merge PR #144,#145,#146,#147,#148,#150
* Make use of EDID utilities optional on modern kernels
* Fallback to mainboard serial if bios serial is not available
* Merge PR #152, #156, #158, #159
* Fix issue for ipdiscover
* Indicate god value for memory
* Use now Parse::EDID module to retrieve monitor infomrations
* Merge PR #161, #163, #164, #165, #169, #170, #172, #173, #174
2.4.1
* Add the date of installation for debian/ubuntu packages
* Add support for zfs
* Rewrite cpu bsd
* Fix some bugs on Repository/Deb.pm file
* Ipmi.pm : fix fatal typo
* Bios.pm : fix "invalid" message
* UUID.pm : fix "invalid" message
* Virtualization : fix for Proxmox
* Fix for vlans
* Fix virsh out
2.4
* Add test to switch 'waitpid command' according to OS
* change bazar revision number to git revision number
* ipdiscover: fix default latency
* Ignore files which are created during installation
* Fix and improve comments in module.conf
* Fix some typos
* Update MANIFEST
* Fix code which disables SSL certificate verification
* Fix storage parameters from smartctl
* Fix markdown syntax and typo in README.md
* Use pkg command on Solaris 11 to create the Software Inventory
* Upgraded memconf to v3.14 (support for SPARC T7-4 and S7-2)
* New feature: repositories inventory
* Fix problem line 280
* Issues corrections
* Retrieve info for apfs formatted drive
* correct df check for AIX
* Fix regexp for listing network interfaces on macOS
* Update Mem.pm
* Update Agent.pm
2.3
* Suppress functions can_run, can_load, can_read from Backend. Those from Common.pm are now used
* Update libraries snapshot for release
2.2
* Suppress reference message to support "No support detected. Registration key: N/A"
* Linux storages now supports Megacli raid
* Merge Mysteq PR "centos-release is the correct file to check"
* Merge XANI PR "read edid from sysfs, fallback to old method if no monitor is found"
* Fix bugs in Network.pm and IP.pm files (OS Linux)
* Correction for usb inventory
* Retrieve Docker container informations
* Update memconf command to last revision
* Add enhancement support for Xen xl command (xm command already present)
2.2rc1
* Update memconf command to last revision
* Fix Bug #1466748 Interface Detection Infiniband MAC wrong
* Fix Bug #1423905 Failed HTTP auth if password contains # character
* Fix syntax error in BSDpkg.pm file
* HPUX/Solaris: use --nosoftware instead of --nosoft
* Correction of graphics resolution
* Retrieve speed and duplex from a different way
* Enhancement: unix agent can now report battery inventory
* Enhancement: unified agent can retrieve lxc container
* Suppress --nosoft option
* Fix Bug #1440626 Typo error in Alpha/CPU.pm
* Fix Bug #1438719 pkg_list has been deprecated on FreeBSD so no software inventory is gathered on those systems
* Fix Bug #1438021 Support s390x processors
* Fix Bug #1436702 Wrong disk size
* Fix Bug #1435675 AIX typo error in Hardware.pm
* Fix Bug #1431844 données de HDD SAS/SAN manquantes AIX 5.3, 6.1 et 7.1
* Fix Bug #1420073 Linux/Archs/i386/CPU.pm reports incorrect CPU information
* Fix Bug #1409671 PROCESSORS bad value on PowerPC arch
* Fix Bug #1405167 Presentation of OS Name and OS Version
* Fix Bug #1389255 Nombre d'interfaces recherchees
* Fix Bug #1376787 [UNIX Agent] Feature request: report Fusion-io cards
* Fix Bug #1364123 created script perl for xenserver
* Fix Bug #1350240 --nosoftware does'nt work on aix
* Fix Bug #1342038 Wrong data for cores on Unix Agent 2.1.1
* Fix Bug #1322088 CPU show 0 on VM libvirt
* Fix Bug #1319683 libvirt VM partial detection
* Fix Bug #1293588 CPU on Ubuntu may not be detected because of `arch` command and Dumper reference
* Fix Bug #1246427 CentOS Linux 6 not identified
* Fix Bug #1201734 Hyper-V virtual machines not recognized as "Virtual Machine" by agent
* Fix Bug #1159742 Ipmi.pm does not load Net::IP at the right place
* Fix Bug #1064296 ipv4 handling fix
2.1.1
* Add number of socket in Linux/Archs/i386/CPU.pm
* Add hyperthreading support in Linux/Archs/i386/CPU.pm
* Fix Bug #1312830 about missing CPU information
* Update memconf command to last revision
* Add new file to detect Oracle distro
* Fix CPU.pm which couldn't retrieve multi socket processors
* Fix Bug #1045356 about regression in ifconfig parsing
* Fix a mistake in tag in 6876.xml
* Move lib/Ocsinventory/Oracle and lib/Ocsinventory/Apache directories in lib/Ocsinventory/agent/Modules directory
* Fix a mistake in Hooks.pm which makes Download.pm and Snmp.pm not loaded by agent
* Fix problem on path of arch command
* Fix debug trace in CPU.pm
* Fix a translation mistake in MacOSX agent French installer
2.1
* Fix #Bug 1272425 about status of libvirt virtual machines not reported
* Fix blueprint about installation date in the report of the installed software
* Fix blueprint about UUID value in the hardware Table
* Fix Bug #1247190 about default gateway as gateway for all interfaces under Linux
* Add new screen code for edid (PTS)
* Add new module to retrieve Nvidia cards
* Add new module to retrieve virtual machines on vmware workstation
* Return corrected values for storage under Fedora 19
* Fix Bug #1247190 about default gateway as gateway for all interfaces under Linux
* Add new screen code for edid (PTS)
* Add new module to retrieve Nvidia cards
* Add new file to detect CentOS distro
* Add new module to retrieve virtual machines on vmware workstation
* Return corrected values for storage under Fedora 19
* Fix Bug #1206514 about enhancing modules loading to allow directories
* Fix a bug in Common.pm about processes data marked as virtualmachines data
* Fix Bug #1216935 about Mac user agent not generating UUID
* Fix Bug #1237682 about RPM.pm INSTALLDATE format not always accepted by MySQL
* Retrieve the speed of network card
* Add a new log message when unable to scan a SNMP devices in Snmp.pm
* Fix problem about IP address tests in Snmp.pm
* Remove "-pP" option passed to nmap in Snmp.pm
* New module to retrieve NetApp devices using SNMP
* New module to retrieve Sun devices using SNMP
* Add new value to BIOS.pm
* Fix bugs in CUPS.pm and Usb.pm files
* Retrieve new values for CPU
* Update memconf command to latest version
* Fix bugs about usb in Lsusb.pm and Common.pm
* Add retrieve of usb connected devices
* Fix Bug #1198088 about wrong data for processors under 2.1 RC1
* Fix bug about SNMP v3 in 9.pm
* Fix bug about custom network scanning in Snmp.pm
* Add retrieve of video memory size
* Fix Bug #1169675 about error message about SSL_verify_mode of SSL_VERIFY_NONE under Fedora 18
2.1rc1
* Fix Bug #1095989 about a bad regex in Libvirt.pm
* Fix Bug #1032393 about softwares bot inventoried vi dpkg-query
* Add custom SNMP MIBs XML copy from sources in postinst.pl
* Getting monitor serial number in MacOS/Video.pm
* Add a new configuration option for SSL certificate check in MacOSX agent installer
* Add new screen codes for edid
* Fix Bug ##1117110 about missing number of CPU socket
* Add availibility to reforce a package deployment
* Code rewrite in Common.pm to prevent sending empty XML tags to OCS server
* Fix Bug #1086086 about uses of initialized value in Snmp.pm
* Fix Bug #1087270 about zombie processes when running in daemon mode
* Fix Bug #1086078 about use of initialized value
* Fix Bug #1070788 about zip packages support
* Fix Bug #1045356 about ifconfig parsing issue (Fedora >=17)
* New availability to scan custom network with SNMP using a network address received from server
* Fix Bug #1049626 about Qemu virtualization not detected on proxmox
* Fix Bug #1040197 about VLAN interface AIX support
* Add detect CPU architecture
* AIX memory module change
* Add many informations about CPU (l2cachesize, status, socket designation, cores number)
* Fix Bug #882574 about parsing of dmidecode fails on SMBIOS warning
* Fix Bug #984699 about the Output of 'ps' in VirtualBox module is displayed in stdout
* Fix Bug #571655 about the Wrong Sys:Syslog usage
* Retrieve family, serial number, number of processors, clockrate for BSDsystems
* New module for inventoring Oracle databases
* Multiples monitors patch added
* Fix Bug #1023670 about memconf not working with HP-UX 11.31
* New version of Gentoo.pm
* New Backend/Virtualization/Parallels.pm module for Parallels virtual machines inventory
* Plugin Processes moved as module
* Fix Bug #911492 about Freebsd Storage drives not being reported
* Fix Bug #911491 about Freebsd CPU info not reporting properly
* Fix Bug #873377 about Installed packages on Gentoo
* Add OS/Linux/LVM.pm module for Logical Volume Manager support
* New Snmp/231.pm module for Fujistu devices
* postinst.pl can now be launched in non-interactive mode using new "--nowizard" launch option
* Adding all the configuration options as launching arguments in postinst.pl
* Adding new interactive questions about "debug", "logfile", "ssl" and "ca" configuration options in postinst.pl
* Download.pm uses LWP useragent initiated by Network.pm for SSL checks
* Download.pm uses LWP useragent initiated by Network.pm for info and frags files downloads
* Network.pm can use LWP version 6 SSL useragent options
* New --ca configuration option to specify a CA certificates file path for SSL certificate checks
* New --ssl configuration option to enable/disable SSL certificate checks
* Customize SNMP scans using a special XML format received from server
* Getting network devices MAC address during SNMP scans
* Availibity to scan any networks SNMP devices using nmap or ping scans
* SNMP v3 available for SNMP scans
* Add new --ssl configuration option to enable or disable certificate check during SSL communications
* Change 'SERIAL' field name and add checksum for inventory XML CPUS section
* Now getting MANUFACTURER and SERIALNUMBER in Snmp/3375.pm
* Add new fields in setSnmpLoadBalancer() method in Common.pm
* Fix Bug #1085020 about ERR_ALREADY_IN_HISTORY message that should be success
* Fix bug with SNMP cartridges and trays in Common.pm
* Add new MacOS/Controller.pm module to get controllers inventory under MacOSX
* Add new MacOS/Slots.pm module to get slots inventory under MacOSX
* Add missing DESCRIPTION field in addController() in Common.pm
* Set debug and lazy options to 0, in generated ocsinventory-agent.cfg file by macOSX graphic installer, if check boxes are not selected
* Add a new configuration option to set lazy mode in MacOSX graphic installer
* Improve MacOSX postinstall script to able to deploy MacOSX agent using NetInstall
2.0.5
* Fix Bug #953968 about MacOSX OCSNG.app crash under MacOSX 10.4 64 bits
* Fix bug about illegal hexadecimal digit in Snmp/Host_Resources_Mib.pm
* Fix segfault and buffer overflow bugs in ipdiscover.c
* Improve OCS MacOSX agent internationalization support
* Back to previous pane after wrong OCS server address warning in MacOSX installer
2.0.4
* Improve memory slots detection under MacOSX 10.7 in MacOS/Mem.pm
* Force OCSNG.app to become the topmost window in tools/macosx/ocsng_app-xcode/main.m
* Fix Bug #901570 about wrong printer name if no printer found in MacOS/Printers.pm
* Solving CPU and memories inventory detection under MacOSX Snow Leopard and MacOSX Lion
* Modifying MacOSX backend files to use the new Mac::Sysprole Perl module version
* Fix Bug #887534 about invalid CREATEDATE in lib/Ocsinventory/Agent/Backend/OS/Linux/Drives.pm
2.0.3
* Fix Bug #881406 about security issue due to snmp_com.txt file which is no longer used
* Fix Bug #874269 about wrong conversion if hard drive >= TB in MacOS/Storages.pm
* Fix Bug #879487 about a misplaced object release in ocs_agent_configPane.m
2.0.2
* Fix bug on "Debug Mode" checkbox in MacoSX installer
* Fix bug while sending ERR_DOWNLOAD_INFO message in Donwload.pm
* Fix Bug #856161 about installer problems on MacOSX Tiger
2.0.1
* New SNMP data using If_Mib.pm: IP address, netmask, gateway and routing informations
* Use the "public" SNMP community if no community defined in OCS server configuration
* Various bug fixes in Snmp.pm
* New 2.0 MacOSX integration
* Bug #798428 about standalone agent building
* Change variable names to lowercase in Snmp/3375.pm
* Fix a closedir omission in Solaris/Packages.pm
* Modify releases tarball name when building it using make dist command
* Various patches for CPU, Bios and Drives detection for HPUX systems
* Fix Bug #781732 about a missing chomp() in Processes.pm
2.0
* Fix Bug #778692 about using authentication when sending messages in Download.pm
* Patch from Yoann Le Bihan for Solaris zones support
* Fix Bug #586321 about wrong version comparison in Vmsystem.pm
* Bug #772436 about download end message report in Download.pm
* Display support log received from PROLOG
* Various patches for Snmp/9.pm module (Cisco)
* Add --nolocal option to desactivate local mode even if it is set in config file or command line
* Fix Bug #767290 about /etc/sysconfig/ocsinventory-agent server settings ignore (only for Redhat like distributions)
* Only inventory vitualmachines which have an UUID in VirtualBox.pm to prevent inventoring USB devices or shared folders as virtualmachines
2.0rc4
* Complety clean the disastrous treatments of accountinfos while receiving it from server,storing it in file and adding it in inventory
* Fix UTF8 problems due to XML::Simple::XMLIn()
2.0rc3
* Fix Bug #720635 about lspci usage on old Linux distributions
* Fix Bug #720626 about Gentoo packages with hyphen in their names
* Fix a bug with the use of pacman tool on ArchLinux. We now launch the real packages manager instead of the famous game ;) ;)
* Avoid perl errors when no answer from OCS server
* Enhance logging in Snmp.pm and Download.pm when disabling this modules (local mode or prerequisites not OK)
* Patches from Bernhard Denner to enhance CPU and memry detection on old SUN solaris workstations
* Patch from Bernhard Denner to enhance dhcp-leases files detection on Linux systems
2.0rc2
* Add a new cleanXml() subroutine in Common.pm to clean non printable characters in both standard inventory and SNMP inventory
* Various patches for Snmp/9.pm module (Cisco)
* Add a new addSnmpCPU() subroutine in Common.pm
* Disabling Download.pm if agent running in local mode
2.0rc1
* Add download_start_handler to check if Net::SSLeay can be load and disable Download.pm if not
* Add Net::SNMP optional dependency in README file.
* Delete Win32 from backend
* Various patches for 9.pm and If_Mib.pm to enhance ethernet ports speed display (Françs Mermet)
* New SNMP modules for Juniper, Futjitsu and F5 vendors (Françs Mermet)
* Fix Bug #682689 about missing data for disk when can't run lshal command (Bernhard Denner)
* Add a warning message about user privacy in man page for --scan-homedirs option
* Various patches for 8072.pm an If_Mib.pm (Françs Mermet)
* Change timeout for Backend modules from 180 to 600 seconds
* Change timeout for Backend modules from 180 to 600 seconds
* Back on the ipdiscover binary from the old OCS Linux Agent to make network scans lighter than Nmap. Ipdiscover binary is only available under Linux systems
* Use LaunchDaemons instead of LaunchAgents in MacOSX package
* Fix SSL errors if no URL is given by the server in Snmp.pm
* Do SNMP scans and treatments only if asked by the server
* Delete some useless logs in debug for SNMP constructors and standard MIBs modules
* Change oid_value in snmp_info subroutine in Printer_Mib.pm
* New SNMP 2620.pm module for Checkpoint Software Technologies constructor (Françs Mermet)
* Add new "DEVICEPORT" and "DEVICETYPE" fields in addSnmpnetwork() in Common.pm
* 311.pm and 8072.pm use setSnmpComputer() to set the type of SNMP device
* Add a new addSnmpInput() subroutine in Common.pm
* Fix a bug in addSnmpSwitch subroutine in Common.pm
* Replace SetSnmpSwitch() subroutine by SetSnmpSwitchInfos() in Common.pm
* Set right fields for AddSnmpSwitch() subroutine in Common.pm
* Fix various bug on snmp_oid_run subroutine for constructors and standard MIB modules
* Fix various mistakes and missing fields in snmp subroutines in Common.pm
* Fix a warning due to deprecated syntax in 3ware.pm
* Fix a warning due to deprecated syntax in 3ware.pm
* Fix a catastrophic performance issue by preventing to run sysctl at every line of demidecode output to get CPU informations on BSD systems
* Snmp.pm now download snmp_com.txt file to get informations about SNMP communities for scans using HTTPS
* New subroutines called "getHttpFile" and "getHttpsFile" in Network.pm to download files easily using HTTP or HTTPS.
* Fix bugs and minor mistakes in Common.pm and If_Mib.pm
* Add Lenovo EDID for monitors (Adam Buchbinder)
* Disabling Snmp.pm if agent running in local mode
* Fix a warning if network interface is down in Ipdiscover.pm
* Enhance inventory initialization for a better modularity
* Local mode can now use the "inventory_handler" hook
* Various patches for SNMP constructors or standard MIB module (Françs Mermet)
* Prevent a bug in using Default.pm (Françs Mermet)
* Add "ACR" and "EPI" EDID ID for monitors (Adam Buchbinder)
* Fix Bug #597752 about TYPE and VOLUMN fiels reversal for BSD systems.
* Fix Bug #612515 to report network interface that don't have an IP address (Mick K)
* Don't take care of host with no MAC address in Nmap.pm
* Add the SOFTWARE field in addSnmpCard subroutine
* Enhance Printer_Mib.pm to add information about printer status and printer error state
* Snmp.pm now use Default.pm to launch standard MIB modules by default (Françs Mermet)
* Upgrade several SNMP contructors/standard MIB modules
* Add a new SNMP constructor module for Lexmark
* Add a new SNMP module for the standard Entity MIB.
* Add a new SNMP module to load standard MIB modules by default
* Add new subroutines for SNMP XML feeding for informations about switches, network cards, blades, firewalls etc....
* Correct a log mistacke in Printer_Mib.pm
* New 11.pm module to enable SNMP scans on HP devices
* Get the SNMP device MACADDR from PROLOG resp to generate the SNMPDEVICEID in Snmp.pm
* Add new subroutines in Common.pm for special SNMP XML feed or SNMP special treatments
* New Printer_Mib.pm module to get SNMP printers informations
2.0 alpha Tue, 27 Jul 2010 22:27:27 +0100
* Snmp.pm use flushXMLTags() from Common.pm to flush the content of $common->{xmltags}
* Modifying the inventory backend to use functions from Common.pm instead of Inventory.pm
* New Snmp.pm for SNMP scans integration. It comes with its constructors modules to enhance scans results (a lot of beers to Françs Mermet to thank himfor his help)
* Modifying postinst.pl to include Ocsinventory::Agent::Modules::Snmp
* Agent.pm : add $logger object in Ocsinventory::Agent::Common instantiation
* Common.pm : adding the can_run(), can_load(), can_read() and runcmdi() generic methods. Adding the use of the $logger object
* Common.pm : add a new field 'TYPE' in setSnmpCommons()
* Agent.pm now uses the new Networks.pm methods and add the $network object in the $context hash
* Networks.pm now gives generic methods to send a XML to OCS server and receive a XML from OCS server
* New addInput() method in Common.pm to add mouses and keyboards in inventory
* Donwload.pm now use 'get_path' and 'already_in_array' functions from the new Common.pm
* Common.pm : Replace the former Common.pm by a new one. Common.pm now give a lot of methods for other agent modules
* Agent.pm : instanciate Ocsinventory::Agent::Common object and add a reference to it in $context
* Use of the Nmap::Parser perl module to correct the very buggy Nmap implementation for Ipdiscover
* Various patches for Solaris support (Lucas MASSE)
* Fix the network speed data oblivion in Inventory.pm. The network speed can now be added in Network.pm of the several OS backends
* Put the prolog_reader hook run at the right place to avoid an error if the agent failed to reach the server
* Enhance dom0 support for Xen support (Guillaume ROUSSE)
* Add bios informations for Xen PV hosts (Guillaume ROUSSE)
* Fix Bug #552727 about getting processes that are running in Solaris (Emengao)
* Add the availiability to disable a module using start_handler hook
* Debug and code cleaning in Download.pm
* Fix Bug #552097
* Add XML::SAX::Expat module include
* Replace {REQUEST} and {ADM} by {xmlroot} in xml handling for a better and better readability
* Remove text about Win32 port in the README file
* Correct a bug in Hooks.pm to pass inventory or prolog to modules
* Add headers for the modules logs
* Correct a bug in postinst.pl when removing the old Linux agent
* Ocsinventory::Agent::Option:: namespace is now Ocsinventory::Agent::Modules::
* Modules now use Perl's object system
* Hooks are now methods and not simple subroutines
* Hook.pm is now Hooks.pm
* Use of a new context hash in Agent.pm
* CompatibilityLayer.pm is now Hook.pm
* Calling hooks only in Agent.pm
* Update HPUX support (Francois Mermet)
* Verify ID value received by server in Download.pm
* Verify the network syntax in Nmap.pm
* Replace an hard coded pattern in Linux/devices.pm
* Removing non posix cp option in Download.pm
* Upgrade to memconf V2.13
* Add an in contrib example of script to identify specific software (Simon CLARA)
* An example of script to use tarball to identify installed software
* HP-UX: initial support, tested on RP3440
* Solaris/Network: support Zone
* Solaris: use regex to identify CPU class
* Improve the README about non-interactive installation
* MacOSX: Correctly identify the CPU frequency on MacOSX 1.6 French
1.1.2.1 Tue, 12 Oct 2010 19:42:41 +0100
* Fix a secutiry bug due to the use of ExtUtils::Installed in Backend.pm.
See http://bugs.debian.org/590879 and http://www.debian.org/security/2009/dsa-1828
for more informations.
Thanks to Remi Collet for his report.
1.1.2 Sun, 27 Dec 2009 17:24:43 +0100
* Avoid problem with dmidecode -V output on RHEL3.9 (Remi COLLET)
* Fix internal --delaytime handling. That's seconds, not hours!
* Download.pm: improve a error message
1.1.1 Mon, 21 Dec 2009 22:38:12 +0100
* NETWORKS/VIRTUALDEV should be 1 or 0
* FreeBSD: Fix CPU detection (David DURIEUX)
* Virtualization::Qemu, fix kvm detection
* Don't run brctl if it's not installed
* Various wording fixes (Vincent KNECHT)
* Improve README (Barius DRUBECK)
* Get serial number from ext4 partition if ext4dev driver is used
* LP: #494908 Agent fails to retrieve info file when a package is
activated only with the server name (Pascal DANEK)
* LP: #495398 Fix RedHat version detection (Stéane URBANOVSKI)
* LP: #490774 Fix PowerPC CPU detection on Linux, thanks darkpep for
the bug report
1.1 Fri, 06 Nov 2009 16:07:08 +0100
* addMemorie() renamed to addMemories(), this had been broken during
the addMemories() . addMemory() transition
* Debug mode: msg "check function failed" changed to "ignored" since
the fails may be wanted by the check() function
* CompatibilityLayer: $self->{params} changed to $self->{config},
this restore the debug mode in Download.pm
* Continue XML::Inventory functions name clean up. Rename:
- addSlots() calls to addSlot()
- addMemories() calls to addMemory()
* Move ocsinventory-agent POD documentation frol Ocsinventory::Agent
to the ocsinventory-agent shell script. So now the manpage has the
correct name
* Fix RPM output parsing (Remi COLLET)
* VMWareESX: avoid breakage is VM has spaces in its name
(Christian Michallek)
* Try to detect kvm --uuid value
* Makefile.PL, check for Net::SSLeay
* Move Ocsinventory::Agent in a .pm and add a wrapper script to load
in order to by able to process --devlib
* Parallels.pm: doesn't use sudo anymore and check for
--scan-homedirs
* Prune 'Mac OS X' from the version on Mac + typo fixes (Scott HANNAHS)
* POD doc, add a paragraph about the config file
* LP: #462529, Fix EDID screen detection, thanks Sergio MERINO
* Use boolean for networks/virtualdev
* Generic/Screen: chomp uuencode output
* Generic/Screen: HSD code for "Hanns.G" (Remi COLLET)
* postinst.pl, put user $PATH in /etc/cron.d/ocsinventory-agent
1.1_beta1 Fri, 18 Sep 2009 11:54:12 +0200
* Can use Net::CUPS to find the default printer
* AIX: Hide procfs in Filesystem
* OS::Linux::Storages, correctly retrieve the serial (Vladimir ELISSEEV)
* load $http_proxy env settings and --proxy option is available
* Add OS::Linux::Distro::NonLSB::ArchLinux (Julien SAFAR)
* New Backend OS::Generic::Processes
* Linux/BSD: detect DNS servers config
* Solaris: Better output for $OSVErsion (Vladimir ELISSEEV)
* Solaris: Sun Fire T1000 patches for memory (Vladimir ELISSEEV)
* Solaris: memory SPARC Enterprise T5220 (Vladimir ELISSEEV)
* Solaris: CPU SPARC Enterprise T5220 (Vladimir ELISSEEV)
* Solaris: CPU SPARC Enterprise T5220 (Vladimir ELISSEEV)
* Linux: split the /proc/cpuinfo parsing depending on the arch
* Linux: drop Linux::Controllers which is duplicated with
Generic::Lspci::Controllers (Vladimir ELISSEEV)
* AIX: Various fixes in Memory.pm (Sebastien DAGNICOURT)
* AIX: Storages.pm, Virtual disks support and fixes (Sebastien DAGNICOURT)
* Backend.pm: Bump the default timeout from 30 to 180 secondes
* Agent/XML/Inventory: Fix when version == 0, bug found by neisen
* AIX: device type adjustment (Sebastien DAGNICOURT)
* Solaris: Sun-Fire-V440 support (Sebastien DAGNICOURT)
* Add a missing space if the name banner in --debug mode
* Agent/XML/Inventory.pm: Add FROM and INSTALLDATE fields in software
list and LASTLOGGEDUSER DATELASTLOGGEDUSER
in HARDWARE (Nicolas EISEN)
* Initialize etcdir key even if there is no config file
* CompatibilityLayer: correctly set $debug
* CompatibilityLayer: better log messages
* getOptionInfoByName return an array ref now
* rename getOptionInfoByName to getOptionsInfoByName
* --debug print the XML on STDERR
* Rename the params key to config to avoid ambiguity
with $params
* set HARDWARE/DEFAULTGATEWAY (Nicolas EISEN)
* RPM: collect the install date and the size (Nicolas EISEN)
* Linux: Collect LASTLOGGEDUSER and DATELASTLOGGEDUSER (Nicolas EISEN)
* DPKG: collect the Installed-Size (Nicolas EISEN)
* Linux: Collect the ext{2,3,4} and xfs serial number
* Linux: Collect the ext{2,3,4} creation date
* Add a warning when no certificat is found
* Turns off alarm once it's backend run is finish
* Fix the IPMI module detection
* Linux: Store the PCISLOT and the driver name
* NETWORKDS, only store Networks with an address
* Linux: detect virtual network device
* Linux: Store CONTROLLERS/DRIVER and CONTROLLERS/PCISLOT
* Linux: Collects xfs, ext{2,3,4} and vfat label
* runs the backend module from main() it's possible to
reuse the Backend object.
* Linux: filter non standard MAC address returned by ifconfig like
00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 mac
* Linux: Fix the Uptime check()
* Preliminary libvirt support
* Partial rewrite of the Download.pm backend
* Add a warning if the user is no root, thanks Nicolas EISEN and
Sylvain LUCE
* SPARC-Enterprise M4000 and M5000 support (Sylvain LUCE)
* Libvirt: collect VCPU info (Philippe LIBAT)
* Add Virtualization::Xen module (Philippe LIBAT)
* Solaris: add a warning if memconf is not in $PATH
* Switch the XML content from ISO-8859-1 to UTF-8, BTW we force
LC_ALL=C...
* Fix the history flood in Download.pm (Pascal DANEK)
https://sourceforge.net/tracker/index.php?func=detail&aid=2806585&group_id=58373&atid=487492
* Stores PCIID in CONTROLLERS/PCIID
* Storage the monitor EDID string in BASE64 and UUENCODE
* Linux: Storages: reorganize the code base and use lshal
* Linux: Drives, complete inforamtions with lshal (Nicolas EISEN)
* Linux: fix the PowerPC CPU detection
https://sourceforge.net/tracker/?func=detail&atid=487492&aid=2043221&group_id=58373
* Warns the user during the install process if one of
the recommended module is not installed
* Update out copy of memconf, thanks WeatherDave who notified the new
revision and of course Tom Schmidt who do a great job
* MacOSX: Avoid a scalar used has hash ref error, thanks Adadov
* Save VIDEOS/MEMORY and VIDEOS/RESOLUTION
* MacOSX: Correctilly detect Up/Down network interfaces
(David OLIVIER)
* AddNetwork() doesn't ignore network with no IP address
(David OLIVIER)
* add --backend-collect-timeout parameter (Nicolas EISEN)
* MacOSX: convert the IP mask from hex (David OLIVIER)
* MacOSX: add a workaround to avoid Mac::SysProfile failure on
MacOSX 10.5.7 (David OLIVIER)
* Add Virtualization::VirtualBox module (Nicolas EISEN)
* Add Virtualization::Qemu module (Nicolas EISEN)
* Add Virtualization::Vmsystem module (Nicolas EISEN)
* Better smartctl detection (Nicolas EISEN)
* optimization and vm users detection Virtualization::VirtualBox (Nicolas EISEN)
* Add Virtualization::VmwareFusion module (Walid NOUH)
* Don't use hdparm prior 9.2.2 anymore to avoid crap in kernel log, see
http://forums.ocsinventory-ng.org/viewtopic.php?pid=20768
* Correctly detect ipmitool
* Solaris: i86pc Memory support (Jean-Françs BOUCHER)
* Solaris Zone support (Maurizio BERTABONI)
* Always send tag, even if server already has one
* Add the byHand software collect method (Séstien DAGNICOURT)
* add logging to can_read(), can_load() and can_run()
* use addUser() instead of setHardware()
* Add the runcmd() in the Backend modules
1.0.1 Sun, 22 Mar 2009 20:48:49 +0100
* Fix a typo in Ocsinventory::Agent::Backend::OS::AIX::Memory
1.0 Sun, 22 Mar 2009 20:14:26 +0100
* Hide warning messages when tw_cli or hpacucli are not present on CentOS
* Avoid unnecessary about missing 'http://' in local mode
* Ipmi.pm: use can_run do detect ipmitool
* LSB.pm: properly use can_run
* Avoid a warning in CompatibilityLayer.pm in local mode
* Improve the README file
* Avoid a warning at runtime if rpm is not correctly installed
* BSD: Detect AMD64 arch (David DURIEUX)
* HP.pm: force detection even if slot 1 is 0 (Remi COLLET)
* HP.pm minor clean up + indentation
* HP.pm send the $model as NAME to avoid NAME == 'unknown' (Remi COLLET)
* New backend module ServeRaid for IBM ServeRAID card (Remi COLLET)
* Linux::Storages, fix the hdparm call (Remi COLLET)
* OS::Generic::Dmidecode::Bios, fix for RHEL2 dmidecode (Remi COLLET)
* launch backend modules with a 30sec timeout
* post-inst.pl: use prompt() from ExtUtils::MakeMaker to avoid
unexpected error with cpan
* avoid the "No LSB modules are available." warning message
* Backend: --debug print a warning when arun() function is not found
* Fix the Debian/Ubuntu detection for non lsb system
* postinst.pl also drops /etc/cron.d/ocsinventory-client if the user
wants to drop the old linux_agent
* Backend::OS::Solaris::Memory: use the Logger instead of "print"
* Solaris: Drop unwanted spaces around OSVERSION and STORAGES/DESCRIPTION
* Solaris: Avoid warning if the user can't use fstyp
* MANIFEST.SKIP: ignore .git/ and .gitignore
* add a workaround for http://rt.cpan.org/Ticket/Display.html?id=38067
* build-perl-tree.sh use cpanp and perl 5.10 now
* Backend.pm: do a eval around require File::Find
* Add a workaround to find the backend modules for PAR::Packer
* Backend.pm: internal change, now do eval 'use $pmodule' instead of require
* fix serialnum detection in Lsilogic.pm and Adaptec.pm (Edouard GAMIN)
* Makefile.PL: drop wait(), not used
* Makefile.PL: fix a syntax error
* add tools/makedist.sh to document the workaround used to avoid
http://rt.cpan.org/Public/Bug/Display.html?id=43060
* Fix --logfile=/somewhere.log, see
http://forums.ocsinventory-ng.org/viewtopic.php?id=3092
* tools/build-perl-tree.sh, add a new script
* Don't print ugly error if next_timefile can't be saved
* OS::Linux::Domains, improve the way it deals with multiple
domaine entries (Remi COLLET)
* AIX: Record the last memory Slot (Wilfried BRUNKEN)
http://sourceforge.net/tracker/?func=detail&atid=487492&aid=2350694&group_id=58373
* Bump 0.0.10 to 1.0 because it's the first release to be officially part
of the OCSInventory distribution
0.0.10beta2 Wed, 24 Sep 2008 23:41:21 +0200
* README: add a not about the $PATH varible on Solaris.
* Added extra section support for backends (Pascal DANEK)
* Fix the way submodules are disabled with $runMeIfTheseChecksFailed
* Linux: Use lsb_release if presents to detect the OS, this will fix
the Ubuntu detection
* Hide a Perl warning if the agent is run by the user want the last_state
file is missing
* Add Ipmi backend module (Jean PARPAILLON)
* Drop the control characters from the inventory XML
https://sourceforge.net/tracker/index.php?func=detail&aid=2100606&group_id=58373&atid=487492
* Apply a little change in standalone.sh that may fix the ParserDetails.ini problem,
thanks tharoun
0.0.10beta1 Thu, 04 Sep 2008 18:16:49 +0200
* Fix a "ocs server name" => URI side effect (Pascal DANEK)
* Download::Store: used absolute path to "cp" on STORE action (Pascal DANEK)
* Download::Store: set -dpR flags to "cp" (Pascal DANEK)
* Solaris: Replaced hostid in serialnumber by real serialnumber (Nicolas DORFSMAN)
(SUNWsneep becomes mandatory on sparc)
* Solaris: Return only one IP address (trying to guess which one corresponds to hostname) (Nicolas DORFSMAN)
* Solaris: return disks SERIALNUMBER and FIRMWARE as XML fields (Nicolas DORFSMAN)
* Redirection and stderr issue on Solaris (Nicolas DORFSMAN)
- Removed close of stderr fd
- Modified lspci and screen check() to avoid pollution of stdout/stderr
* fix the previous changelog entry, the 0.0.9.1 fix had been done by Nicolas DORFSMAN
* postinst.pl checks for MANIFEST present
* improve the backend module detection by also scanning the symlinked directory
* add the --devlib flag to load ./lib only if wanted and remove '.' from the directory to scan
with File::Find.
* import the can_run, can_load and can_read functions in the Backend modules
* the backend module can have no check function, in this case OCS assume it's ok
* apply a patch by Etienne GUILLAUMONT to fix CPU detection on AIX 4
* standalone.sh checks PAR::Packer presence now
* only inventory installed .deb
* postinst.pl: accept another vardir if the first one was invalide
https://sourceforge.net/tracker/?func=detail&atid=487492&aid=1961771&group_id=58373
* postinst.pl Download.pm correctly activated in modules.conf if the user needs it
* add MacOSX support thanks to Wes YOUNG (Wes YOUNG)
- Added tools/darwin/ support scripts/code for OS X enterprise deployment
* add the follow_skip==2 flag to File::Find in Backend.pm so it doesn't detect the same
file two time
* import of backend module for RAID controller on Linux (3ware, Adaptec, HP and Lsilogic)
(Edouard GAMIN)
* remove a warning in Debug mod, if a backend module has no run() function
* don't crash in Daemon mode if the server is unreachable (Wes YOUNG)
* Net::IP is just (strongly) suggested now
* fix --basevardir so it really accepts a parameter, thanks Gubluts from the forum who
pointed out the bug
* postinst.pl use which to find ocsinventory-agent location
* Makefile.PL, Perl 5.6 doesn't have Config::config_re, I call it from an eval now
* Added --delaytime option as commandline / .cfg file adjustable (Wes YOUNG)
* standalone.sh, don't use grep -v since it's not POSIX
* doesn't die if Storable.pm is missing like with perl 5.6
* avoid a warning with gzip -h on AIX if Compress::Zlib is missing
* README: depends on Perl 5.8
* README: On solaris the Makefile needs gmake
* README: Add a note about crontab and PATH
* Linux: redirect hdparm error to /dev/null
* postinst.pl yes/no questions have a default value now
* postinst.pl fix a bug in the import of the old ocsinv.adm
https://sourceforge.net/tracker/index.php?func=detail&aid=1991668&group_id=58373&atid=487492
* postinst.pl doesn't create two vardir directories anymore
* do not print a wrning is --nosoftware is used. Thanks Knarfling and Remi who pointed the issue
out.
http://forums.ocsinventory-ng.org/viewtopic.php?pid=12569
* fix the POD documentation, some mistakes were detected by Perl 5.10's perldoc.
* the agent doesn't crash anymore if ocsinv.adm or ocsinv.conf is corrupted
* Makefile.pl: install memconf on Solaris
* Solaris: apply patches to use memconf for CPU, Drives and Memory (Christoph HALMES)
0.0.9.2 04/18/2008 Bug fix
* Add /ocsinventory in the server path if the user enter just the hostname
https://sourceforge.net/tracker/?func=detail&atid=487492&aid=1945865&group_id=58373
0.0.9.1 04/03/2008 Bug fix
* fix a error in the previous release that was forcing the local mode (Nicolas DORFSMAN)
https://sourceforge.net/tracker/?func=detail&atid=487492&aid=1945863&group_id=58373
0.0.9 04/01/2008 April Fool release!
* Added fallback for --lazy if no prolog freq was found and server error (Pascal DANEK)
* Fixed accountinfos handling bugs (Pascal DANEK)
* Changed --wait behaviour (--wait=number_of_seconds || "server") (Pascal DANEK)
* PROLOG_FREQ is handled in prolog phase (Pascal DANEK)
* the random value for file_nexttime is computed only if prolog_freq has changed since last prolog (Pascal DANEK)
* import the documentation documentation by adding a description of the
agent and pointer to the official website
* --nosoft option renamed to --nosoftware, --nosoft still works but with a warning
* add --basevardir to be able to use a specific place to store the var file
* add the --lazy parameter: send an inventory only if the a random delay between 0 and PROLOG_FREQ had been run over. Useful for package maintainer (Remi COLLET)
* return 1 to the shell if the agent failed to contact the server
* postinst.pl asks for the basevardir
* postinst.pl write the modules.conf
* OS::Linux::Network::Networks, correctly reset the ipaddress before every loop so
now a network can't have the address of the previous one
* rename the key $params->{conffile} to $params->{accountconfig}
* fix the way accountinfo information are stored
* improve (a bit) tools/standalone.sh to avoid error if people launch it
from the tools directory
* --server is ignore if --local is in use
* adjust Backend::OS::Generic::Screen to be able to use monitor-edid with DVI link (Remi COLLET)
* OS::Linux::Storages, add NEC as a know manufacturer add assume the manifacturer is Seagate if
the model doesn't match the others and begin with ST (rjhill)
* fix the CPU detection on Linux Sparc64 and ARM (Linksys NSLU2)
* improve the Solaris version detection by reading the /etc/release file (Nicolas DORFSMAN)
* Solaris: fix the MAC addresses when the leading zeros is missing (Jean-Jacques MICHEL)
* Solaris: Add publisher is possible in the software list (Nicolas DORFSMAN)
* Solaris: improve the hard drive detection (Nicolas DORFSMAN)
* postinst.pl can remove the previous linux_agent
* postinst.pl reuse linux_agent old config file to set the default server and tag
* return the SERIALNUMBER and the FIRMWARE on Linux with hdparm, the feature is not supported
yet by the server (egamin)
0.0.8.1 02/20/2008
* postinst.pl, correctly save the realm, do not override the password
* Added "CAPTION" field to memory (Pascal DANEK)
* Fix a bug with "NUMSLOTS" memory field (Pascal DANEK)
* improve the parsing of the config file to accept quote and spaces in the value
* postinst.pl save the configfile with 0600 right since the server
password maybe be stored in it
* standalone.sh doesn't scan the inc/ directory anymore
* remove the BUNDLE packages which seem to break the install process
* change Solaris::CPU to use psrinfo -v to get the CPUs which works fine on x86
* fix a path error in Ocsinventory::LoggerBackend::File (Remi COLLET)
* fix: don't send the inventory if the server doesn't need it (Remi COLLET)
0.0.8 02/05/2008
* fix the deviceid and old_deviceid handling (Pascal DANEK)
* fix a debug message in Network.pm (Pascal DANEK)
* different fixes on Compress.pm (Pascal DANEK)
* fix an event message name in Option/Download.pm (Pascal DANEK)
* fix the Compatibility Layer with prolog_read hook (Pascal DANEK)
* merge PowerPC and PC code to detect the CPU and improve/fix the regex
* looks for config file in /etc/ocsinventory /usr/local/etc/ocsinventory and
/etc/ocsinventory-agent
* add a pod documentation about the different config files and directories
* Compress::Zlib is required but recommended now. In fact, you need it with
ocs server prior 1.02
0.0.7.2 01/16/2008
* fix the post installation script to avoid invalid cron time
0.0.7.1 01/14/2008
* add setup.sh in the MANIFEST.SKIP to keep it out of the tarball
0.0.7 01/13/2008
* Ocsinventory::Agent::AccountInfo does not warn accountinfofile if runned in debug mode
without root privilege
* fix params->{etcdir} to /etc/ocsinventory, /etc/ocsinventory-agent/modules.conf must be moved
to /etc/ocsinventory/modules.conf
* Solaris: Improve the CPU detection (Olivier ROUSSY)
* AIX: Return the directory with the AIX package name (Olivier ROUSSY)
* Ocsinventory::Agent::XML::Inventory can now write software inventory
value of FILESIZE, FOLDER and PUBLISHER
* processChecksum() and feedInventory() are called by Ocsinventory::Agent::XML::Inventory
directly now
* the server responses are not parsed in the main script anymore
* do not create an inventory if the server doesnn't need it
* new parameters for the backend modules (run and check functions):
- prologresp, the Ocsinventory::Agent::XML::Response::Prolog object returned by
the prolog
- storage: an hashref stored on the harddrive at the end of the execution of the module
* a backend module without a run function is accepted now
* Inventory.pm: add addIpDiscoverEntry() to add host from the same network
* @runMeIfTheseChecksFailed: new optional setting for Backend module
* Ipdiscover is now a backend module and nmap can be used instead of ipdiscover
* --nosoft disable the Ocsinventory::Agent::Backend::OS::Generic::Packaging modules
* Remove the deprecated modules Ocsinventory::Agent::Option::Ipdiscover and
Ocsinventory::Agent::Option::Update
* the check function of the backend accepts the same parameter than the run function
* Linux::Archs::I386 regex are more robust
* perldoc documentation for the ocsinventory-agent command
* minor improvment on the Makefile.PL
* change the way --server parameter is read. Now we can have a full URL, --remotedir
is now useless
* fix: correctly load the last_state
* improve the Makefile.PL by using inc::Module::Install and adding new check
* add a --version parameter and improve the --help
* come with bundled dependency to simply the build process
* fix the login/passwd/realm authentification
* remove Agent/Pid.pm, I've to prepare a better system to keep the pid first
* try to read the config in /usr/local/etc/ocsinventory/ocsinventory-agent.cfg if the
standard one is missing
0.0.6.2 07/16/2007 Bug fix release
* remove a debug "die" in the code
0.0.6.1 06/12/2007 Bug fix release
* Fix an undef value in Ocsinventory::Agent::Backend::OS::BSD::Mem
* AIX: retrieve correctly the MAC address of some FibberChannel card
* now standalone.sh will try to find every module before the build to
avoid unexplicated error
0.0.6 06/07/2007
* Enable "verbose" is debug is turned on
* AIX: Ocsinventory::Agent::Backend::OS::AIX::Networks rewrote
* AIX: Memory.pm, remove the spaces from the end of the DESCRIPTION
* add standalone.sh, a script designed to prepare a stand-alone binary of the agent
* AIX: Retrieve all the gateway of every subnet instead of just the default one
* Config.pm renamed to AccountConfig.pm
* New flag: --stdout to print the inventory directly on STDOUT
* If the use want write on the system var directory, the agent create one in
~/.ocsinventory/var
* The agent setting can be preinitialised with /etc/ocsinventory/ocsinventory-agent.cfg or
~/ocsinventory/ocsinventory-agent.cfg.
* remove two debug messages printed during accountinfo rewrite and the
daemon starting process
* remove a stupid check in Ocsinventory::Agent::AccountConfig, the
accountconfig file was not written unless the file was already present
* add a recMkdir function in ocsinventory-agent to create directory recursivly
* do not process checksum in local mode
0.0.5 04/17/2007
* AIX: use lslpp -c -l to find installed packages
* AIX: fixes on CPU.pm, Networks.pm and Memory.pm
* AIX: fetch the serial number with lscfg unless it was found with lsvpd
* add the .ocs extension to local written files
* with --local flag: don't not warn if last_state doesn't exit
* Solaris: retrieve installed package
* downgrade some message important from info to debug
* read screen serial number in the EDID (DDC screen)
* Xorg.pm replaced by Screen.pm
* Screen.pm all the data are read from EDID now
* Initial Linux PPC support (tested in Debian Etch).
thanks Walid Nouh for the hardware
* Apply patch by Remi Collet to fix an issue with Linux distro detection and Perl 5.6.1
* Turn of STDERR during the module execution to avoid useless message (e.g: foo: not found)
use --debug to turn them back
* If the system side vardir can't be created. The agent try to create one in ~/.ocs-inventory-agent
* Add a THANKS file
0.0.4 03/20/2007
* use of gzip when Compress:Zlib is not avalaible. OCS server 1.01 and
prior are not supported.
* dmidecode parsing improved
* lspci stuffs moved to generic
* Linux: find Wifi connection
* fix: pass correctly the logger to the modules
* don't write the last_state if the connexion failed
* Deals correctly with the accountinfo if it's internaly stored in a
array ref
* BSD support by Thierry Lacoste
UnixAgent-2.10.0/LICENSE 0000664 0000000 0000000 00000043103 14323200667 0014505 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
UnixAgent-2.10.0/MANIFEST.SKIP 0000775 0000000 0000000 00000000412 14323200667 0015375 0 ustar 00root root 0000000 0000000 CVS/
.git
.bzr
^00
^.gitignore$
^.cvsignore$
.svn
.merge
^blib
^_build
^Build$
^cover_db
^nytprof
^Makefile(\.old)?$
^MANIFEST\.
^MYMETA\.
^pm_to_blib$
^run-postinst
~$
\.bak$
\.old$
\.sw[a-z]$
\.#
\.swp
^Ocsinventory-agent.*
/tarballs/
^setup.sh
.*\.tmp
var/
UnixAgent-2.10.0/META.yml 0000775 0000000 0000000 00000001643 14323200667 0014757 0 ustar 00root root 0000000 0000000 ---
abstract: 'Ocs-Inventory unified Agent for UNIX, Linux and MacOSX'
author:
- 'OCS Inventory Team'
build_requires:
ExtUtils::MakeMaker: 6.59
configure_requires:
ExtUtils::MakeMaker: 6.59
distribution_type: module
dynamic_config: 1
generated_by: 'Module::Install version 1.19'
license: gpl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: 1.4
name: Ocsinventory-Unix-Agent
no_index:
directory:
- inc
recommends:
Compress::Zlib: 0
Net::IP: 0
Nvidia::ml: 0
Proc::Daemon: 0
Proc::PID::File: 0
requires:
Digest::MD5: 0
File::Temp: 0
LWP: 0
XML::Simple: 0
perl: 5.6.0
resources:
homepage: http://www.ocsinventory-ng.org
bugtracker: https://github.com/OCSInventory-NG/UnixAgent/issues
repository: https://github.com/OCSInventory-NG/UnixAgent
irc: irc://irc.freenode.net/#ocsinventory-ng
license: http://opensource.org/licenses/gpl-license.php
version: 2.4.2
UnixAgent-2.10.0/Makefile.PL 0000775 0000000 0000000 00000011405 14323200667 0015455 0 ustar 00root root 0000000 0000000 BEGIN {
# Avoid installation issue introduced by perl 5.24.1 removing '.' path from
# @INC to avoid possible module injection in normal running perl scripts
push @INC, '.' if ( $^V && $^V gt 'v5.24' );
}
use inc::Module::Install;
use English qw(-no_match_vars);
use Config;
require 'lib/Ocsinventory/Agent/Config.pm';
# Hack to be able to run a post install script
sub MY::postamble
{
my $re;
$re = '
install :: all pure_install doc_install
$(NOECHO) $(NOOP)';
$re .= "\n\t[ ! -f run-postinst ] || $^X postinst.pl\n";
return $re;
}
my $version = $Ocsinventory::Agent::Config::VERSION;
name 'Ocsinventory-Unix-Agent';
include 'Module::AutoInstall';
abstract 'OCS Inventory unified Agent for UNIX, Linux and MacOSX';
license 'gpl';
repository 'https://github.com/OCSInventory-NG/UnixAgent/';
version $version;
perl_version '5.006';
authors 'OCS Inventory Team';
# mandatory dependencies
requires 'Digest::MD5' => undef;
requires 'XML::Simple' => undef;
requires 'LWP' => '5.8';
requires 'File::Temp' => undef;
requires 'Net::IP' => undef;
recommends 'IO::Socket::SSL' => undef;
recommends 'Compress::Zlib' => undef;
recommends 'Proc::Daemon' => undef;
recommends 'Proc::PID::File' => undef;
# test dependencies
test_requires 'IO::Socket::SSL' => '0';
test_requires 'Net::SNMP' => '0';
test_requires 'LWP::Protocol::https' => '0';
# deployement or https communication
recommends 'Crypt::SSLeay' => undef;
recommends 'LWP::Protocol::https' => undef;
# inventory
recommends 'Net::CUPS' => undef;
recommends 'Parse::EDID' => undef;
# network
recommends 'Net::SNMP' => undef;
recommends 'Net::Netmask' => undef;
recommends 'Net::Ping' => undef;
recommends 'Nmap::Parser' => undef;
resources
bugtracker => 'https://github.com/OCSinventory-NG/Unixagent/issues',
homepage => 'http://www.ocsinventory-ng.org',
IRC => 'irc://irc.freenode.net/#ocsinventory-ng',
repository => 'https://github.com/OCSinventory-NG/Unixagent';
install_script 'ocsinventory-agent';
# We want a release bundled with the needed dependency to be able to
# prepare a standalone binary with PAR::Packer
if ($ENV{OCS_BUNDLE_RELEASE}) {
foreach my $module (qw/Archive::Zip HTML::Parser LWP URI XML::NamespaceSupport Net::IP Net::Netmask HTML::Tagset Proc::Daemon Module::ScanDeps PAR::Packer AutoLoader PAR PAR::Dist File::Remove YAML::Tiny Getopt::ArgvFile ExtUtils::Install ExtUtils::ParseXS XML::SAX XML::Simple/) {
bundle $module;
requires $module;
}
}
#Ugly hack to include ipdiscover binary compilation and install for Linux systems
if ($^O =~ /^linux$/i && can_cc()) {
my $cc=$Config::Config{cc};
my $ld=$Config::Config{ldflags};
my $cf=$Config::Config{ccflags};
my $op=$Config::Config{optimize};
system("$cc $cf $ld $op resources/ipdiscover/ipdiscover.c -o ipdiscover");
if (-f 'ipdiscover') {
install_script 'ipdiscover';
}
}
if (defined ($ENV{PERL_AUTOINSTALL}) || defined ($ENV{PERL_AUTOINSTALL})) {
unlink 'run-postinst';
} else {
open POSTINST, '>run-postinst' or die $!;
close POSTINST;
}
if (!can_use('Compress::Zlib')) {
print "Please install Compress::Zlib if you use an OCS server prior 1.02.\n";
}
if (!can_use('Net::SSLeay')) {
print "Please install Net::SSLeay if you want to use the software deployment.\n";
}
if (!can_run('ipdiscover') && !can_run('nmap')) {
print "Please install nmap ";
print "or ipdiscover " if $^O =~ /^linux$/i;
print "if you want to use the network ".
"discover feature.\n";
}
if (!can_use('Net::IP')) {
print "Net::IP is strongly recommended since it's required to retrieve "
."network information\n";
}
if (!can_use('Net::Netmask')) {
print "Net::Netmask is strongly recommended since it's required to retrieve "
."snmp information\n";
}
if (!can_use('Proc::Daemon') || !can_use('Proc::PID::File')) {
print "Please install Proc::Daemon and Proc::PID::File if you ".
"want to use the daemon mode.\n";
}
my $archname;
eval { # config_re is not available on Perl 5.6
my @t = Config::config_re('archname');
$archname = $t[0];
};
if ($^O =~ /(linux|bsd)/i && (!$archname ||$archname =~ /(i[3456x]86|x86_64|amd64)/i)) {
foreach (qw/dmidecode lspci/) {
if (!can_run($_)) {
print "\n";
print "[WARNING] $_ is needed if you want a complete inventory on x86 and AMD64/x86_64.\n";
print "\n";
}
}
}
if ($^O =~ /^darwin$/ && !can_use('Mac::SysProfile')) {
print "\n";
print "[WARNING] Mac::SysProfile are needed on MacOS to detect most of the device information.\n";
print "\n";
requires 'Mac::SysProfile' => undef;
}
# memconf is needed by Solaris backend module
if ($^O =~ /^solaris$/i) {
install_script 'memconf';
}
#for i in inc/BUNDLES/* ; do rm -rf `basename $i` ;done`
#auto_install;
WriteAll;
UnixAgent-2.10.0/README.md 0000664 0000000 0000000 00000013060 14323200667 0014756 0 ustar 00root root 0000000 0000000
OCS Inventory UnixAgent
Some Links:
Ask question |
Installation |
Website |
OCS Professional
Ocsinventory-Agent is an agent for ocsinventory NG. It supports Linux,
Solaris and AIX. *BSD support is in progress.
Prerequisites
- Perl 5.8 minimum
#### The following modules are needed:
- Digest::MD5
- XML::Simple
- Net::IP optional, it is only needed to compute the network information
- LWP
- Mac::SysProfile 0.0.5 : this module is need on MacOSX to collect the device informations.
- To get SSL communications working (for packages deployment or HTTPS communications to OCS server), you need these modules:
- Crypt::SSLeay if you use LWP prior to version 6
- LWP::Protocol::https if you use LWP version 6 or more
- Net::CUPS is used to detect the printer
- Net::SNMP to scan network devices using SNMP
- To enhance SNMP feature with custom networks scans, you need these modules:
- Net::Netmask
- Net::Ping or Nmap::Parser
- Data::UUID is used to create a unique id for every machine
- Parse::EDID is used to inventory monitor and will replace monitor-edid from Mandriva.
#### The following commands are needed:
- dmidecode on Linux and *BSD (i386, amd64, ia64) => dmidecode is required to read the BIOS stats.
- lspci on Linux and *BSD (pciutils package) => lspci is required to list PCI devices.
- sneep on Solaris/sparc, you must install sneep and record the Serial Number with it (download it from http://www.sun.com/download/products.xml?id=4304155a)
- To get the serial number of the screen you will need one of these tools:
- monitor-edid from Mandriva is needed to fetch the monitor. A package is available in Fedora repository. information http://wiki.mandriva.com/en/Tools/monitor-edid
- get-edid from the read-edid package
- ipmitool if you want to collect information about IPMI
- Nmap (v3.90 or superior) to scan network devices for Ipdiscover
#### The following PERL modules are optional:
- Proc::Daemon Daemon mode
- Proc::PID::File brings the pid file support if Proc::Daemon is installed
- Compress::Zlib
#### The following module is needed if you plan to prepare a tarball or install directly from the Bazaar devel branch. (See SOURCES below.):
- Module::Install
Build / Install
Once the archive is unpacked, use these commands:
```
perl Makefile.PL
make
make install
```
If you want to turn off the interactive post install script, just do (instead of perl Makefile.PL)
```
PERL_AUTOINSTALL=1 perl Makefile.PL
```
You can also run the agent from the tarball directory. In this case, use the `--devlib` flag to load the library from the local directory.
You need to launch the agent with root privilege. For debugging you can try to launch it with the `-l` flag:
Ex: `ocsinventory-agent -l /tmp --debug`
It's also possible to run directly from the tarball directory:
`sudo ./ocsinventory-agent --devlib --server http://foo/ocsinventory`
Note
Solaris:
- Sun Studio seems to be needed to build the dependency.
- The generated Makefile needs gmake to be exectuted
- The default installation will install the binary in /usr/perl5/5.XXXXX/bin, set your $PATH variable according to that.
Crontab:
- If you use crontab to launch the agent you'll probably have to redefine the PATH. For example, just add something like: `PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin` At the beginning of the cron file.
## Contributing
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Add your changes: `git add folder/file1.php`
4. Commit your changes: `git commit -m 'Add some feature'`
5. Push to the branch: `git push origin my-new-feature`
6. Submit a pull request !
## License
OCS Inventory is GPLv2 licensed
The memconf script is maintained by Tom Schmidt
http://www.4schmidts.com/memconf.html
Copyright © 1996-2017 Tom Schmidt
memconf is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
Ocsinventory::Agent::Backend::Virtualization::Vmsystem uses code from imvirt:
Authors:
Thomas Liske
Copyright Holder:
2008 (C) IBH IT-Service GmbH [http://www.ibh.de/]
License: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
Ocsinventory::Agent::Backend::OS::Linux::Storages::Adaptec uses code from Parse-Arcconf:
https://github.com/kumy/Parse-Arcconf
License and Copyright:
Copyright (C) 2012 Mathieu Alorent
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License. See http://dev.perl.org/licenses/ for more information.
UnixAgent-2.10.0/THANKS 0000664 0000000 0000000 00000004433 14323200667 0014416 0 ustar 00root root 0000000 0000000 Olivier ANDREOTTI: AIX, Solaris patches
Thierry LACOSTE: BSD portage
Didier LIROULET: Installation script
Remi COLLET: bug fixes and Fedora/RedHat maintainer
Walid NOUH: gave access to PowerPC hardware to help the portage
Olivier ROUSSY: minor patches
Dennis CABOOTER: FreeBSD maintainer
Pierre CHIFFLIER: Debian maintainer
Nicolas DORFSMAN: Solaris patches
Jean-Jacques MICHEL: Solaris patches
Etienne GUILLAUMONT: AIX4 CPU detection
Wes YOUNG: MacOSX support and patches
Edouard GAMIN: RAID devices support for Linux
Christoph HALMES: Solaris patches
Jean PARPAILLON: IPMI backends and patches
David DURIEUX: AMD64 detection on BSD systems
Wilfried BRUNKEN: patch for memory detection on AIX
Vladimir ELISSEEV: various patches
Julien SAFAR: ArchLinux support
Damien MAURAN: MacOSX packaging, doc and support
Sebastien DAGNICOURT: AIX and Solaris patches
Nicolas EISEN: patches
Sylvain LUCE: Sun M5000 and M4000 support
Philippe LIBAT: patchs and Xen support
David OLIVIER: MacOSX patches
Jean-François BOUCHER: Solaris patch
Scott HANNAHS: MacOSX patches
Maurizio Bertaboni: Solaris Zone support
Scott HANNAHS: patch
Sergio MERINO: patch
Vincent KNECHT: wording patch
Barius DRUBECK: documentation patch
Stéphane URBANOVSKI: patch
Jerome LEBASE: Solaris patches
François MERMET: HP-UX support and SNMP integration
Dmitry ILYIN: Patches
Guillaume ROUSSE: various patches for Xen support
Lucas MASSE: various patches for Solaris support
Adam BUCHBINDER: various patches
Bernhard Denner: various patches
Yoann Le Bihan: Solaris patches
Andreas Xenos: MacOSX patches and Parallels support
Francois Laupetre: LVM modules
Christophe Borivant
Viper233: patch monitor edid
Alexandre Bossot: oracle module
Javier Barroso: VLAN interface on AIX
Yves GUIMARD: download.pm patch for zip files
Marco Tizzoni: Host_Resources_Mib.pm and Agent.pm patches
Matthias Vedrines: patch + various modules
Trois Six: patch
DerJoern: patch
Serge Roux: patch
Guillaume Lecerf: Xen support
Mikkel Paulson: patch
XANI: patch
Philippe Beaumont: patch
lhchin: patch
pilch-cit: patch
lj6: patch
nerijus: patch
GSponda: patch
JHeidinga: patch
Unrankar: patch
jfcoz: patch
xalasys-luc: patch
stweil: patch
ivmaks: patches
MikaelUranker: patches
nnn-dev: patches
jmechnich: patches
matt335672: patches
temperatur: patch
RudyLaurent: patches
guimard: patches
UnixAgent-2.10.0/contrib/ 0000775 0000000 0000000 00000000000 14323200667 0015137 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/contrib/Tarballs.pm 0000664 0000000 0000000 00000002746 14323200667 0017252 0 ustar 00root root 0000000 0000000 # Write by Simon CLARA 2010-01-25
#
# The complete name of the package
# the path MUST be valid or the package won't be loaded
package Ocsinventory::Agent::Backend::OS::Generic::Tarballs;
use strict;
# I need to declare $runAfter because of the strict mode
use vars qw($runAfter);
# The package must be run after OS::Generic
$runAfter = ["Ocsinventory::Agent::Backend::OS::Generic"];
# This is the check function. The agent runs it just once the module is loaded.
# If the function return false, the module and its children are not executed
# eg: OS::Linux and OS::Linux::* won't executed if this run() function return
# false
# Check if we are on a linux server
sub check { $^O =~ /^linux$/ }
# uncomment this if you want check for FreeBSD server
# sub check {can_run("pkg_info")}
# its the main function of the script, it's called during the hardware inventory
sub run {
my $params = shift;
# I need to get the inventory object to update it
my $inventory = $params->{inventory};
# our software are in /usr/local/src/
foreach (`ls /usr/local/src/*.{bz2,tar.gz}`){
/^(\/.*\/)(\S+)-(\d+\S*)(\.tar.gz|\.bz2)$/i;
my $name = $2;
my $version = $3;
my $comments = "Software in /usr/local/src/ \n".`$2 --version`;
# and I updated the information collected
$inventory->addSoftwares({
COMMENTS => $comments,
NAME => $name,
VERSION => $version
});
}
}
1;
UnixAgent-2.10.0/contrib/cron/ 0000775 0000000 0000000 00000000000 14323200667 0016100 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/contrib/cron/ocsinventory-agent.cron 0000664 0000000 0000000 00000001637 14323200667 0022630 0 ustar 00root root 0000000 0000000 #!/bin/bash
NAME=ocsinventory-agent
exec >>/var/log/$NAME/$NAME.log 2>&1
[ -f /etc/sysconfig/$NAME ] || exit 0
source /etc/sysconfig/$NAME
export PATH
i=0
while [ $i -lt ${#OCSMODE[*]} ]
do
if [ ${OCSMODE[$i]:-none} == cron ]; then
OPTS=
if [ ! -z "${OCSPAUSE[$i]}" ]; then
OPTS="--wait ${OCSPAUSE[$i]}"
fi
if [ ! -z "${OCSTAG[$i]}" ]; then
OPTS="$OPTS --tag=${OCSTAG[$i]}"
fi
if [ "z${OCSSERVER[$i]}" = 'zlocal' ]; then
# Local inventory
OPTS="$OPTS --local=/var/lib/$NAME"
elif [ ! -z "${OCSSERVER[$i]}" ]; then
# Remote inventory
OPTS="$OPTS --lazy --nolocal --server=${OCSSERVER[$i]}"
if [ ! -z "${OCSPROXYSERVER[$i]}" ]; then
OPTS="$OPTS --proxy=${OCSPROXYSERVER[$i]}"
fi
fi
echo "[$(date '+%c')] Running $NAME $OPTS"
/usr/sbin/$NAME $OPTS
fi
((i++))
done
echo "[$(date '+%c')] End of cron job ($PATH)"
UnixAgent-2.10.0/contrib/cron/ocsinventory-agent.logrotate 0000664 0000000 0000000 00000000303 14323200667 0023654 0 ustar 00root root 0000000 0000000 # Rotate OCS Inventory NG agent logs daily, only if not empty
# Save 7 days old logs under compressed mode
/var/log/ocsinventory-agent/*.log {
daily
rotate 7
compress
notifempty
missingok
}
UnixAgent-2.10.0/contrib/cron/ocsinventory-agent.sysconf 0000664 0000000 0000000 00000001223 14323200667 0023342 0 ustar 00root root 0000000 0000000 ##
## OCS Inventory "Unix Unified Agent" Configuration File
## used by the supplied cron job
##
## Add tools directory if needed (tw_cli, hpacucli, ipssend, ...)
PATH=/sbin:/bin:/usr/sbin:/usr/bin
## Mode, change to "cron" to activate
OCSMODE[0]=none
## can be used to override the ocsinventory-agent.cfg setup.
# OCSSERVER[0]=your.ocsserver.name
#
## If you need an HTTP/HTTPS proxy, fill this out
# OCSPROXYSERVER[0]='http://user:pass@proxy:port'
##
## corresponds with --local=/var/lib/ocsinventory-agent
OCSSERVER[0]=local
## Wait before inventory
OCSPAUSE[0]=100
## Administrative TAG (optional, must be filed before first inventory)
OCSTAG[0]=
UnixAgent-2.10.0/contrib/cron/systemd/ 0000775 0000000 0000000 00000000000 14323200667 0017570 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/contrib/cron/systemd/ocsinventory-agent-daily.timer 0000664 0000000 0000000 00000000336 14323200667 0025572 0 ustar 00root root 0000000 0000000 [Unit]
Description=Run OCS Inventory once per day
[Timer]
OnCalendar=daily
OnUnitInactiveSec=86000
Unit=ocsinventory-agent.service
RandomizedDelaySec=900
AccuracySec=900
Persistent=true
[Install]
WantedBy=timers.target
UnixAgent-2.10.0/contrib/cron/systemd/ocsinventory-agent-hourly.timer 0000664 0000000 0000000 00000000303 14323200667 0026004 0 ustar 00root root 0000000 0000000 [Unit]
Description=Run OCS Inventory Hourly (if server permits)
[Timer]
OnCalendar=hourly
Unit=ocsinventory-agent.service
RandomizedDelaySec=10
Persistent=true
[Install]
WantedBy=timers.target
UnixAgent-2.10.0/contrib/cron/systemd/ocsinventory-agent-onboot.timer 0000664 0000000 0000000 00000000267 14323200667 0025773 0 ustar 00root root 0000000 0000000 [Unit]
Description=Run OCS Inventory shortly after boot
[Timer]
OnBootSec=900
Unit=ocsinventory-agent.service
RandomizedDelaySec=10
Persistent=true
[Install]
WantedBy=timers.target
UnixAgent-2.10.0/contrib/cron/systemd/ocsinventory-agent.service 0000664 0000000 0000000 00000000274 14323200667 0025013 0 ustar 00root root 0000000 0000000 [Unit]
Description=OCS Inventory Agent
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/libexec/ocsinventory-agent/ocsinventory-agent.cron
[Install]
WantedBy=multi-user.target
UnixAgent-2.10.0/cpanfile 0000664 0000000 0000000 00000000751 14323200667 0015206 0 ustar 00root root 0000000 0000000 requires 'XML::Simple', '>= 2.12';
requires 'Compress::Zlib', '>= 1.33';
requires 'Net::IP', '>= 1.20';
requires 'Switch', '>= 2.0';
requires 'Proc::Daemon', '>= 0.20';
requires 'Proc::PID::File', '>= 1.20';
requires 'Net::SNMP', '>= 6.0';
requires 'Net::Netmask', '>= 1.9';
requires 'LWP::Protocol::https', '>= 6.0';
requires 'Parse::EDID', '>= 1.0';
requires 'Data::UUID', '>= 1.2';
requires 'LWP::UserAgent', '>= 6.4'; UnixAgent-2.10.0/etc/ 0000775 0000000 0000000 00000000000 14323200667 0014252 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/etc/cron.d/ 0000775 0000000 0000000 00000000000 14323200667 0015435 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/etc/cron.d/ocsinventory-agent 0000664 0000000 0000000 00000001252 14323200667 0021216 0 ustar 00root root 0000000 0000000 #
# File generated by OCS Inventory NG Unified Unix Agent setup
#
################################################################################
#
# OCS Inventory NG Unified Unix Agent
#
# Copyleft 2007 Didier LIROULET
# Web: http://www.ocsinventory-ng.org
#
# This code is open source and may be copied and modified as long as the source
# code is always made freely available.
# Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
################################################################################
#
# Launch OCS Inventory NG Agent once a day under root account, at HH:MM
#
MM HH * * * root /usr/bin/ocsinventory-agent > /dev/null 2>&1
UnixAgent-2.10.0/etc/default/ 0000775 0000000 0000000 00000000000 14323200667 0015676 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/etc/default/ocsinventory-agent 0000664 0000000 0000000 00000000023 14323200667 0021452 0 ustar 00root root 0000000 0000000 SERVER="localhost"
UnixAgent-2.10.0/etc/init.d/ 0000775 0000000 0000000 00000000000 14323200667 0015437 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/etc/init.d/ocsinventory-agent 0000775 0000000 0000000 00000010401 14323200667 0021217 0 ustar 00root root 0000000 0000000 #! /bin/sh
### BEGIN INIT INFO
# Provides: ocs-inventory-agent
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OCS-Inventory Agent
# Description: This script launches OCS Agent as daemon
### END INIT INFO
# Author: Gonéri Le Bouder
#
# Do NOT "set -e"
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="OCS Inventory Agent"
NAME=ocsinventory-agent
DAEMON=/usr/sbin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
DAEMON_ARGS="-d -s $SERVER"
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
#
# Function that starts the daemon/service
#
do_start()
{
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
|| return 1
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
$DAEMON_ARGS \
|| return 2
# Add code here, if necessary, that waits for the process to be ready
# to handle requests from services started subsequently which depend
# on this one. As a last resort, sleep for some time.
}
#
# Function that stops the daemon/service
#
do_stop()
{
# Return
# 0 if daemon has been stopped
# 1 if daemon was already stopped
# 2 if daemon could not be stopped
# other if a failure occurred
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = 2 ] && return 2
# Wait for children to finish too if this is a daemon that forks
# and if the daemon is only ever run from this initscript.
# If the above conditions are not satisfied then add some other code
# that waits for the process to drop all resources that could be
# needed by services started subsequently. A last resort is to
# sleep for some time.
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
[ "$?" = 2 ] && return 2
# Many daemons don't delete their pidfiles when they exit.
rm -f $PIDFILE
return "$RETVAL"
}
#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
#
# If the daemon can reload its configuration without
# restarting (for example, when it is sent a SIGHUP),
# then implement that here.
#
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
return 0
}
case "$1" in
start)
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
stop)
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
esac
;;
#reload|force-reload)
#
# If do_reload() is not implemented then leave this commented out
# and leave 'force-reload' as an alias for 'restart'.
#
#log_daemon_msg "Reloading $DESC" "$NAME"
#do_reload
#log_end_msg $?
#;;
restart|force-reload)
#
# If the "reload" option is implemented then remove the
# 'force-reload' alias
#
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
:
UnixAgent-2.10.0/etc/logrotate.d/ 0000775 0000000 0000000 00000000000 14323200667 0016474 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/etc/logrotate.d/ocsinventory-agent 0000664 0000000 0000000 00000001354 14323200667 0022260 0 ustar 00root root 0000000 0000000 #
# File generated by OCS Inventory NG Unified Unix Agent setup
#
################################################################################
#
# OCS Inventory NG Unified Unix Agent
#
# Copyleft 2007 Didier LIROULET
# Web: http://www.ocsinventory-ng.org
#
# This code is open source and may be copied and modified as long as the source
# code is always made freely available.
# Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
################################################################################
#
# Rotate OCS Inventory NG agent logs daily, only if not empty
# Save 7 days old logs under compressed mode
PATH_TO_LOG_DIRECTORY/*.log {
daily
rotate 7
compress
notifempty
missingok
}
UnixAgent-2.10.0/etc/ocsinventory-agent/ 0000775 0000000 0000000 00000000000 14323200667 0020110 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/etc/ocsinventory-agent/modules.conf 0000664 0000000 0000000 00000000437 14323200667 0022433 0 ustar 00root root 0000000 0000000 # This list of modules will be loaded by the agent at run time.
# To check its syntax do:
# $perl modules.conf
# You must have NO error, else the content will be ignored.
use Ocsinventory::Agent::Modules::Download;
use Ocsinventory::Agent::Modules::SnmpScan;
# DO NOT REMOVE the 1;
1;
UnixAgent-2.10.0/etc/ocsinventory-agent/softwares/ 0000775 0000000 0000000 00000000000 14323200667 0022125 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/etc/ocsinventory-agent/softwares/example.sh 0000775 0000000 0000000 00000000710 14323200667 0024115 0 ustar 00root root 0000000 0000000 #! /bin/bash
# This is an example script for the byHand software collect method
#
# You can create your own script to detect the installed software
# and install them in /etc/ocsinventory/softwares
#
#ligne=$(ls --version| head -n 1)
#
#soft=$(echo $ligne | cut -f1 -d'('| sed 's/ //')
#vendor=$(echo $ligne | cut -f2 -d'('| cut -f1 -d')')
#version=$(echo $ligne | cut -f2 -d'('| cut -f2 -d')'|sed 's/ //')
#
#echo "$vendor#$soft#$version#simple test"
#
#
UnixAgent-2.10.0/inc/ 0000775 0000000 0000000 00000000000 14323200667 0014250 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/inc/Module/ 0000775 0000000 0000000 00000000000 14323200667 0015475 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/inc/Module/AutoInstall.pm 0000664 0000000 0000000 00000063016 14323200667 0020300 0 ustar 00root root 0000000 0000000 #line 1
package Module::AutoInstall;
use strict;
use Cwd ();
use File::Spec ();
use ExtUtils::MakeMaker ();
use vars qw{$VERSION};
BEGIN {
$VERSION = '1.14';
}
# special map on pre-defined feature sets
my %FeatureMap = (
'' => 'Core Features', # XXX: deprecated
'-core' => 'Core Features',
);
# various lexical flags
my ( @Missing, @Existing, %DisabledTests, $UnderCPAN, $InstallDepsTarget, $HasCPANPLUS );
my (
$Config, $CheckOnly, $SkipInstall, $AcceptDefault, $TestOnly, $AllDeps,
$UpgradeDeps
);
my ( $PostambleActions, $PostambleActionsNoTest, $PostambleActionsUpgradeDeps,
$PostambleActionsUpgradeDepsNoTest, $PostambleActionsListDeps,
$PostambleActionsListAllDeps, $PostambleUsed, $NoTest);
# See if it's a testing or non-interactive session
_accept_default( $ENV{AUTOMATED_TESTING} or ! -t STDIN );
_init();
sub _accept_default {
$AcceptDefault = shift;
}
sub _installdeps_target {
$InstallDepsTarget = shift;
}
sub missing_modules {
return @Missing;
}
sub do_install {
__PACKAGE__->install(
[
$Config
? ( UNIVERSAL::isa( $Config, 'HASH' ) ? %{$Config} : @{$Config} )
: ()
],
@Missing,
);
}
# initialize various flags, and/or perform install
sub _init {
foreach my $arg (
@ARGV,
split(
/[\s\t]+/,
$ENV{PERL_AUTOINSTALL} || $ENV{PERL_EXTUTILS_AUTOINSTALL} || ''
)
)
{
if ( $arg =~ /^--config=(.*)$/ ) {
$Config = [ split( ',', $1 ) ];
}
elsif ( $arg =~ /^--installdeps=(.*)$/ ) {
__PACKAGE__->install( $Config, @Missing = split( /,/, $1 ) );
exit 0;
}
elsif ( $arg =~ /^--upgradedeps=(.*)$/ ) {
$UpgradeDeps = 1;
__PACKAGE__->install( $Config, @Missing = split( /,/, $1 ) );
exit 0;
}
elsif ( $arg =~ /^--default(?:deps)?$/ ) {
$AcceptDefault = 1;
}
elsif ( $arg =~ /^--check(?:deps)?$/ ) {
$CheckOnly = 1;
}
elsif ( $arg =~ /^--skip(?:deps)?$/ ) {
$SkipInstall = 1;
}
elsif ( $arg =~ /^--test(?:only)?$/ ) {
$TestOnly = 1;
}
elsif ( $arg =~ /^--all(?:deps)?$/ ) {
$AllDeps = 1;
}
}
}
# overrides MakeMaker's prompt() to automatically accept the default choice
sub _prompt {
goto &ExtUtils::MakeMaker::prompt unless $AcceptDefault;
my ( $prompt, $default ) = @_;
my $y = ( $default =~ /^[Yy]/ );
print $prompt, ' [', ( $y ? 'Y' : 'y' ), '/', ( $y ? 'n' : 'N' ), '] ';
print "$default\n";
return $default;
}
# the workhorse
sub import {
my $class = shift;
my @args = @_ or return;
my $core_all;
print "*** $class version " . $class->VERSION . "\n";
print "*** Checking for Perl dependencies...\n";
my $cwd = Cwd::getcwd();
$Config = [];
my $maxlen = length(
(
sort { length($b) <=> length($a) }
grep { /^[^\-]/ }
map {
ref($_)
? ( ( ref($_) eq 'HASH' ) ? keys(%$_) : @{$_} )
: ''
}
map { +{@args}->{$_} }
grep { /^[^\-]/ or /^-core$/i } keys %{ +{@args} }
)[0]
);
# We want to know if we're under CPAN early to avoid prompting, but
# if we aren't going to try and install anything anyway then skip the
# check entirely since we don't want to have to load (and configure)
# an old CPAN just for a cosmetic message
$UnderCPAN = _check_lock(1) unless $SkipInstall || $InstallDepsTarget;
while ( my ( $feature, $modules ) = splice( @args, 0, 2 ) ) {
my ( @required, @tests, @skiptests );
my $default = 1;
my $conflict = 0;
if ( $feature =~ m/^-(\w+)$/ ) {
my $option = lc($1);
# check for a newer version of myself
_update_to( $modules, @_ ) and return if $option eq 'version';
# sets CPAN configuration options
$Config = $modules if $option eq 'config';
# promote every features to core status
$core_all = ( $modules =~ /^all$/i ) and next
if $option eq 'core';
next unless $option eq 'core';
}
print "[" . ( $FeatureMap{ lc($feature) } || $feature ) . "]\n";
$modules = [ %{$modules} ] if UNIVERSAL::isa( $modules, 'HASH' );
unshift @$modules, -default => &{ shift(@$modules) }
if ( ref( $modules->[0] ) eq 'CODE' ); # XXX: bugward compatibility
while ( my ( $mod, $arg ) = splice( @$modules, 0, 2 ) ) {
if ( $mod =~ m/^-(\w+)$/ ) {
my $option = lc($1);
$default = $arg if ( $option eq 'default' );
$conflict = $arg if ( $option eq 'conflict' );
@tests = @{$arg} if ( $option eq 'tests' );
@skiptests = @{$arg} if ( $option eq 'skiptests' );
next;
}
printf( "- %-${maxlen}s ...", $mod );
if ( $arg and $arg =~ /^\D/ ) {
unshift @$modules, $arg;
$arg = 0;
}
# XXX: check for conflicts and uninstalls(!) them.
my $cur = _version_of($mod);
if (_version_cmp ($cur, $arg) >= 0)
{
print "loaded. ($cur" . ( $arg ? " >= $arg" : '' ) . ")\n";
push @Existing, $mod => $arg;
$DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
}
else {
if (not defined $cur) # indeed missing
{
print "missing." . ( $arg ? " (would need $arg)" : '' ) . "\n";
}
else
{
# no need to check $arg as _version_cmp ($cur, undef) would satisfy >= above
print "too old. ($cur < $arg)\n";
}
push @required, $mod => $arg;
}
}
next unless @required;
my $mandatory = ( $feature eq '-core' or $core_all );
if (
!$SkipInstall
and (
$CheckOnly
or ($mandatory and $UnderCPAN)
or $AllDeps
or $InstallDepsTarget
or _prompt(
qq{==> Auto-install the }
. ( @required / 2 )
. ( $mandatory ? ' mandatory' : ' optional' )
. qq{ module(s) from CPAN?},
$default ? 'y' : 'n',
) =~ /^[Yy]/
)
)
{
push( @Missing, @required );
$DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
}
elsif ( !$SkipInstall
and $default
and $mandatory
and
_prompt( qq{==> The module(s) are mandatory! Really skip?}, 'n', )
=~ /^[Nn]/ )
{
push( @Missing, @required );
$DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
}
else {
$DisabledTests{$_} = 1 for map { glob($_) } @tests;
}
}
if ( @Missing and not( $CheckOnly or $UnderCPAN) ) {
require Config;
my $make = $Config::Config{make};
if ($InstallDepsTarget) {
print
"*** To install dependencies type '$make installdeps' or '$make installdeps_notest'.\n";
}
else {
print
"*** Dependencies will be installed the next time you type '$make'.\n";
}
# make an educated guess of whether we'll need root permission.
print " (You may need to do that as the 'root' user.)\n"
if eval '$>';
}
print "*** $class configuration finished.\n";
chdir $cwd;
# import to main::
no strict 'refs';
*{'main::WriteMakefile'} = \&Write if caller(0) eq 'main';
return (@Existing, @Missing);
}
sub _running_under {
my $thing = shift;
print <<"END_MESSAGE";
*** Since we're running under ${thing}, I'll just let it take care
of the dependency's installation later.
END_MESSAGE
return 1;
}
# Check to see if we are currently running under CPAN.pm and/or CPANPLUS;
# if we are, then we simply let it taking care of our dependencies
sub _check_lock {
return unless @Missing or @_;
if ($ENV{PERL5_CPANM_IS_RUNNING}) {
return _running_under('cpanminus');
}
my $cpan_env = $ENV{PERL5_CPAN_IS_RUNNING};
if ($ENV{PERL5_CPANPLUS_IS_RUNNING}) {
return _running_under($cpan_env ? 'CPAN' : 'CPANPLUS');
}
require CPAN;
if ($CPAN::VERSION > '1.89') {
if ($cpan_env) {
return _running_under('CPAN');
}
return; # CPAN.pm new enough, don't need to check further
}
# last ditch attempt, this -will- configure CPAN, very sorry
_load_cpan(1); # force initialize even though it's already loaded
# Find the CPAN lock-file
my $lock = MM->catfile( $CPAN::Config->{cpan_home}, ".lock" );
return unless -f $lock;
# Check the lock
local *LOCK;
return unless open(LOCK, $lock);
if (
( $^O eq 'MSWin32' ? _under_cpan() : == getppid() )
and ( $CPAN::Config->{prerequisites_policy} || '' ) ne 'ignore'
) {
print <<'END_MESSAGE';
*** Since we're running under CPAN, I'll just let it take care
of the dependency's installation later.
END_MESSAGE
return 1;
}
close LOCK;
return;
}
sub install {
my $class = shift;
my $i; # used below to strip leading '-' from config keys
my @config = ( map { s/^-// if ++$i; $_ } @{ +shift } );
my ( @modules, @installed, @modules_to_upgrade );
while (my ($pkg, $ver) = splice(@_, 0, 2)) {
# grep out those already installed
if (_version_cmp(_version_of($pkg), $ver) >= 0) {
push @installed, $pkg;
if ($UpgradeDeps) {
push @modules_to_upgrade, $pkg, $ver;
}
}
else {
push @modules, $pkg, $ver;
}
}
if ($UpgradeDeps) {
push @modules, @modules_to_upgrade;
@installed = ();
@modules_to_upgrade = ();
}
return @installed unless @modules; # nothing to do
return @installed if _check_lock(); # defer to the CPAN shell
print "*** Installing dependencies...\n";
return unless _connected_to('cpan.org');
my %args = @config;
my %failed;
local *FAILED;
if ( $args{do_once} and open( FAILED, '.#autoinstall.failed' ) ) {
while () { chomp; $failed{$_}++ }
close FAILED;
my @newmod;
while ( my ( $k, $v ) = splice( @modules, 0, 2 ) ) {
push @newmod, ( $k => $v ) unless $failed{$k};
}
@modules = @newmod;
}
if ( _has_cpanplus() and not $ENV{PERL_AUTOINSTALL_PREFER_CPAN} ) {
_install_cpanplus( \@modules, \@config );
} else {
_install_cpan( \@modules, \@config );
}
print "*** $class installation finished.\n";
# see if we have successfully installed them
while ( my ( $pkg, $ver ) = splice( @modules, 0, 2 ) ) {
if ( _version_cmp( _version_of($pkg), $ver ) >= 0 ) {
push @installed, $pkg;
}
elsif ( $args{do_once} and open( FAILED, '>> .#autoinstall.failed' ) ) {
print FAILED "$pkg\n";
}
}
close FAILED if $args{do_once};
return @installed;
}
sub _install_cpanplus {
my @modules = @{ +shift };
my @config = _cpanplus_config( @{ +shift } );
my $installed = 0;
require CPANPLUS::Backend;
my $cp = CPANPLUS::Backend->new;
my $conf = $cp->configure_object;
return unless $conf->can('conf') # 0.05x+ with "sudo" support
or _can_write($conf->_get_build('base')); # 0.04x
# if we're root, set UNINST=1 to avoid trouble unless user asked for it.
my $makeflags = $conf->get_conf('makeflags') || '';
if ( UNIVERSAL::isa( $makeflags, 'HASH' ) ) {
# 0.03+ uses a hashref here
$makeflags->{UNINST} = 1 unless exists $makeflags->{UNINST};
} else {
# 0.02 and below uses a scalar
$makeflags = join( ' ', split( ' ', $makeflags ), 'UNINST=1' )
if ( $makeflags !~ /\bUNINST\b/ and eval qq{ $> eq '0' } );
}
$conf->set_conf( makeflags => $makeflags );
$conf->set_conf( prereqs => 1 );
while ( my ( $key, $val ) = splice( @config, 0, 2 ) ) {
$conf->set_conf( $key, $val );
}
my $modtree = $cp->module_tree;
while ( my ( $pkg, $ver ) = splice( @modules, 0, 2 ) ) {
print "*** Installing $pkg...\n";
MY::preinstall( $pkg, $ver ) or next if defined &MY::preinstall;
my $success;
my $obj = $modtree->{$pkg};
if ( $obj and _version_cmp( $obj->{version}, $ver ) >= 0 ) {
my $pathname = $pkg;
$pathname =~ s/::/\\W/;
foreach my $inc ( grep { m/$pathname.pm/i } keys(%INC) ) {
delete $INC{$inc};
}
my $rv = $cp->install( modules => [ $obj->{module} ] );
if ( $rv and ( $rv->{ $obj->{module} } or $rv->{ok} ) ) {
print "*** $pkg successfully installed.\n";
$success = 1;
} else {
print "*** $pkg installation cancelled.\n";
$success = 0;
}
$installed += $success;
} else {
print << ".";
*** Could not find a version $ver or above for $pkg; skipping.
.
}
MY::postinstall( $pkg, $ver, $success ) if defined &MY::postinstall;
}
return $installed;
}
sub _cpanplus_config {
my @config = ();
while ( @_ ) {
my ($key, $value) = (shift(), shift());
if ( $key eq 'prerequisites_policy' ) {
if ( $value eq 'follow' ) {
$value = CPANPLUS::Internals::Constants::PREREQ_INSTALL();
} elsif ( $value eq 'ask' ) {
$value = CPANPLUS::Internals::Constants::PREREQ_ASK();
} elsif ( $value eq 'ignore' ) {
$value = CPANPLUS::Internals::Constants::PREREQ_IGNORE();
} else {
die "*** Cannot convert option $key = '$value' to CPANPLUS version.\n";
}
push @config, 'prereqs', $value;
} elsif ( $key eq 'force' ) {
push @config, $key, $value;
} elsif ( $key eq 'notest' ) {
push @config, 'skiptest', $value;
} else {
die "*** Cannot convert option $key to CPANPLUS version.\n";
}
}
return @config;
}
sub _install_cpan {
my @modules = @{ +shift };
my @config = @{ +shift };
my $installed = 0;
my %args;
_load_cpan();
require Config;
if (CPAN->VERSION < 1.80) {
# no "sudo" support, probe for writableness
return unless _can_write( MM->catfile( $CPAN::Config->{cpan_home}, 'sources' ) )
and _can_write( $Config::Config{sitelib} );
}
# if we're root, set UNINST=1 to avoid trouble unless user asked for it.
my $makeflags = $CPAN::Config->{make_install_arg} || '';
$CPAN::Config->{make_install_arg} =
join( ' ', split( ' ', $makeflags ), 'UNINST=1' )
if ( $makeflags !~ /\bUNINST\b/ and eval qq{ $> eq '0' } );
# don't show start-up info
$CPAN::Config->{inhibit_startup_message} = 1;
# set additional options
while ( my ( $opt, $arg ) = splice( @config, 0, 2 ) ) {
( $args{$opt} = $arg, next )
if $opt =~ /^(?:force|notest)$/; # pseudo-option
$CPAN::Config->{$opt} = $arg;
}
if ($args{notest} && (not CPAN::Shell->can('notest'))) {
die "Your version of CPAN is too old to support the 'notest' pragma";
}
local $CPAN::Config->{prerequisites_policy} = 'follow';
while ( my ( $pkg, $ver ) = splice( @modules, 0, 2 ) ) {
MY::preinstall( $pkg, $ver ) or next if defined &MY::preinstall;
print "*** Installing $pkg...\n";
my $obj = CPAN::Shell->expand( Module => $pkg );
my $success = 0;
if ( $obj and _version_cmp( $obj->cpan_version, $ver ) >= 0 ) {
my $pathname = $pkg;
$pathname =~ s/::/\\W/;
foreach my $inc ( grep { m/$pathname.pm/i } keys(%INC) ) {
delete $INC{$inc};
}
my $rv = do {
if ($args{force}) {
CPAN::Shell->force( install => $pkg )
} elsif ($args{notest}) {
CPAN::Shell->notest( install => $pkg )
} else {
CPAN::Shell->install($pkg)
}
};
$rv ||= eval {
$CPAN::META->instance( 'CPAN::Distribution', $obj->cpan_file, )
->{install}
if $CPAN::META;
};
if ( $rv eq 'YES' ) {
print "*** $pkg successfully installed.\n";
$success = 1;
}
else {
print "*** $pkg installation failed.\n";
$success = 0;
}
$installed += $success;
}
else {
print << ".";
*** Could not find a version $ver or above for $pkg; skipping.
.
}
MY::postinstall( $pkg, $ver, $success ) if defined &MY::postinstall;
}
return $installed;
}
sub _has_cpanplus {
return (
$HasCPANPLUS = (
$INC{'CPANPLUS/Config.pm'}
or _load('CPANPLUS::Shell::Default')
)
);
}
# make guesses on whether we're under the CPAN installation directory
sub _under_cpan {
require Cwd;
require File::Spec;
my $cwd = File::Spec->canonpath( Cwd::getcwd() );
my $cpan = File::Spec->canonpath( $CPAN::Config->{cpan_home} );
return ( index( $cwd, $cpan ) > -1 );
}
sub _update_to {
my $class = __PACKAGE__;
my $ver = shift;
return
if _version_cmp( _version_of($class), $ver ) >= 0; # no need to upgrade
if (
_prompt( "==> A newer version of $class ($ver) is required. Install?",
'y' ) =~ /^[Nn]/
)
{
die "*** Please install $class $ver manually.\n";
}
print << ".";
*** Trying to fetch it from CPAN...
.
# install ourselves
_load($class) and return $class->import(@_)
if $class->install( [], $class, $ver );
print << '.'; exit 1;
*** Cannot bootstrap myself. :-( Installation terminated.
.
}
# check if we're connected to some host, using inet_aton
sub _connected_to {
my $site = shift;
return (
( _load('Socket') and Socket::inet_aton($site) ) or _prompt(
qq(
*** Your host cannot resolve the domain name '$site', which
probably means the Internet connections are unavailable.
==> Should we try to install the required module(s) anyway?), 'n'
) =~ /^[Yy]/
);
}
# check if a directory is writable; may create it on demand
sub _can_write {
my $path = shift;
mkdir( $path, 0755 ) unless -e $path;
return 1 if -w $path;
print << ".";
*** You are not allowed to write to the directory '$path';
the installation may fail due to insufficient permissions.
.
if (
eval '$>' and lc(`sudo -V`) =~ /version/ and _prompt(
qq(
==> Should we try to re-execute the autoinstall process with 'sudo'?),
((-t STDIN) ? 'y' : 'n')
) =~ /^[Yy]/
)
{
# try to bootstrap ourselves from sudo
print << ".";
*** Trying to re-execute the autoinstall process with 'sudo'...
.
my $missing = join( ',', @Missing );
my $config = join( ',',
UNIVERSAL::isa( $Config, 'HASH' ) ? %{$Config} : @{$Config} )
if $Config;
return
unless system( 'sudo', $^X, $0, "--config=$config",
"--installdeps=$missing" );
print << ".";
*** The 'sudo' command exited with error! Resuming...
.
}
return _prompt(
qq(
==> Should we try to install the required module(s) anyway?), 'n'
) =~ /^[Yy]/;
}
# load a module and return the version it reports
sub _load {
my $mod = pop; # method/function doesn't matter
my $file = $mod;
$file =~ s|::|/|g;
$file .= '.pm';
local $@;
return eval { require $file; $mod->VERSION } || ( $@ ? undef: 0 );
}
# report version without loading a module
sub _version_of {
my $mod = pop; # method/function doesn't matter
my $file = $mod;
$file =~ s|::|/|g;
$file .= '.pm';
foreach my $dir ( @INC ) {
next if ref $dir;
my $path = File::Spec->catfile($dir, $file);
next unless -e $path;
require ExtUtils::MM_Unix;
return ExtUtils::MM_Unix->parse_version($path);
}
return undef;
}
# Load CPAN.pm and it's configuration
sub _load_cpan {
return if $CPAN::VERSION and $CPAN::Config and not @_;
require CPAN;
# CPAN-1.82+ adds CPAN::Config::AUTOLOAD to redirect to
# CPAN::HandleConfig->load. CPAN reports that the redirection
# is deprecated in a warning printed at the user.
# CPAN-1.81 expects CPAN::HandleConfig->load, does not have
# $CPAN::HandleConfig::VERSION but cannot handle
# CPAN::Config->load
# Which "versions expect CPAN::Config->load?
if ( $CPAN::HandleConfig::VERSION
|| CPAN::HandleConfig->can('load')
) {
# Newer versions of CPAN have a HandleConfig module
CPAN::HandleConfig->load;
} else {
# Older versions had the load method in Config directly
CPAN::Config->load;
}
}
# compare two versions, either use Sort::Versions or plain comparison
# return values same as <=>
sub _version_cmp {
my ( $cur, $min ) = @_;
return -1 unless defined $cur; # if 0 keep comparing
return 1 unless $min;
$cur =~ s/\s+$//;
# check for version numbers that are not in decimal format
if ( ref($cur) or ref($min) or $cur =~ /v|\..*\./ or $min =~ /v|\..*\./ ) {
if ( ( $version::VERSION or defined( _load('version') )) and
version->can('new')
) {
# use version.pm if it is installed.
return version->new($cur) <=> version->new($min);
}
elsif ( $Sort::Versions::VERSION or defined( _load('Sort::Versions') ) )
{
# use Sort::Versions as the sorting algorithm for a.b.c versions
return Sort::Versions::versioncmp( $cur, $min );
}
warn "Cannot reliably compare non-decimal formatted versions.\n"
. "Please install version.pm or Sort::Versions.\n";
}
# plain comparison
local $^W = 0; # shuts off 'not numeric' bugs
return $cur <=> $min;
}
# nothing; this usage is deprecated.
sub main::PREREQ_PM { return {}; }
sub _make_args {
my %args = @_;
$args{PREREQ_PM} = { %{ $args{PREREQ_PM} || {} }, @Existing, @Missing }
if $UnderCPAN or $TestOnly;
if ( $args{EXE_FILES} and -e 'MANIFEST' ) {
require ExtUtils::Manifest;
my $manifest = ExtUtils::Manifest::maniread('MANIFEST');
$args{EXE_FILES} =
[ grep { exists $manifest->{$_} } @{ $args{EXE_FILES} } ];
}
$args{test}{TESTS} ||= 't/*.t';
$args{test}{TESTS} = join( ' ',
grep { !exists( $DisabledTests{$_} ) }
map { glob($_) } split( /\s+/, $args{test}{TESTS} ) );
my $missing = join( ',', @Missing );
my $config =
join( ',', UNIVERSAL::isa( $Config, 'HASH' ) ? %{$Config} : @{$Config} )
if $Config;
$PostambleActions = (
($missing and not $UnderCPAN)
? "\$(PERL) $0 --config=$config --installdeps=$missing"
: "\$(NOECHO) \$(NOOP)"
);
my $deps_list = join( ',', @Missing, @Existing );
$PostambleActionsUpgradeDeps =
"\$(PERL) $0 --config=$config --upgradedeps=$deps_list";
my $config_notest =
join( ',', (UNIVERSAL::isa( $Config, 'HASH' ) ? %{$Config} : @{$Config}),
'notest', 1 )
if $Config;
$PostambleActionsNoTest = (
($missing and not $UnderCPAN)
? "\$(PERL) $0 --config=$config_notest --installdeps=$missing"
: "\$(NOECHO) \$(NOOP)"
);
$PostambleActionsUpgradeDepsNoTest =
"\$(PERL) $0 --config=$config_notest --upgradedeps=$deps_list";
$PostambleActionsListDeps =
'@$(PERL) -le "print for @ARGV" '
. join(' ', map $Missing[$_], grep $_ % 2 == 0, 0..$#Missing);
my @all = (@Missing, @Existing);
$PostambleActionsListAllDeps =
'@$(PERL) -le "print for @ARGV" '
. join(' ', map $all[$_], grep $_ % 2 == 0, 0..$#all);
return %args;
}
# a wrapper to ExtUtils::MakeMaker::WriteMakefile
sub Write {
require Carp;
Carp::croak "WriteMakefile: Need even number of args" if @_ % 2;
if ($CheckOnly) {
print << ".";
*** Makefile not written in check-only mode.
.
return;
}
my %args = _make_args(@_);
no strict 'refs';
$PostambleUsed = 0;
local *MY::postamble = \&postamble unless defined &MY::postamble;
ExtUtils::MakeMaker::WriteMakefile(%args);
print << "." unless $PostambleUsed;
*** WARNING: Makefile written with customized MY::postamble() without
including contents from Module::AutoInstall::postamble() --
auto installation features disabled. Please contact the author.
.
return 1;
}
sub postamble {
$PostambleUsed = 1;
my $fragment;
$fragment .= <<"AUTO_INSTALL" if !$InstallDepsTarget;
config :: installdeps
\t\$(NOECHO) \$(NOOP)
AUTO_INSTALL
$fragment .= <<"END_MAKE";
checkdeps ::
\t\$(PERL) $0 --checkdeps
installdeps ::
\t$PostambleActions
installdeps_notest ::
\t$PostambleActionsNoTest
upgradedeps ::
\t$PostambleActionsUpgradeDeps
upgradedeps_notest ::
\t$PostambleActionsUpgradeDepsNoTest
listdeps ::
\t$PostambleActionsListDeps
listalldeps ::
\t$PostambleActionsListAllDeps
END_MAKE
return $fragment;
}
1;
__END__
#line 1197
UnixAgent-2.10.0/inc/Module/Install.pm 0000664 0000000 0000000 00000032744 14323200667 0017453 0 ustar 00root root 0000000 0000000 #line 1
package Module::Install;
# For any maintainers:
# The load order for Module::Install is a bit magic.
# It goes something like this...
#
# IF ( host has Module::Install installed, creating author mode ) {
# 1. Makefile.PL calls "use inc::Module::Install"
# 2. $INC{inc/Module/Install.pm} set to installed version of inc::Module::Install
# 3. The installed version of inc::Module::Install loads
# 4. inc::Module::Install calls "require Module::Install"
# 5. The ./inc/ version of Module::Install loads
# } ELSE {
# 1. Makefile.PL calls "use inc::Module::Install"
# 2. $INC{inc/Module/Install.pm} set to ./inc/ version of Module::Install
# 3. The ./inc/ version of Module::Install loads
# }
use 5.006;
use strict 'vars';
use Cwd ();
use File::Find ();
use File::Path ();
use vars qw{$VERSION $MAIN};
BEGIN {
# All Module::Install core packages now require synchronised versions.
# This will be used to ensure we don't accidentally load old or
# different versions of modules.
# This is not enforced yet, but will be some time in the next few
# releases once we can make sure it won't clash with custom
# Module::Install extensions.
$VERSION = '1.14';
# Storage for the pseudo-singleton
$MAIN = undef;
*inc::Module::Install::VERSION = *VERSION;
@inc::Module::Install::ISA = __PACKAGE__;
}
sub import {
my $class = shift;
my $self = $class->new(@_);
my $who = $self->_caller;
#-------------------------------------------------------------
# all of the following checks should be included in import(),
# to allow "eval 'require Module::Install; 1' to test
# installation of Module::Install. (RT #51267)
#-------------------------------------------------------------
# Whether or not inc::Module::Install is actually loaded, the
# $INC{inc/Module/Install.pm} is what will still get set as long as
# the caller loaded module this in the documented manner.
# If not set, the caller may NOT have loaded the bundled version, and thus
# they may not have a MI version that works with the Makefile.PL. This would
# result in false errors or unexpected behaviour. And we don't want that.
my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm';
unless ( $INC{$file} ) { die <<"END_DIE" }
Please invoke ${\__PACKAGE__} with:
use inc::${\__PACKAGE__};
not:
use ${\__PACKAGE__};
END_DIE
# This reportedly fixes a rare Win32 UTC file time issue, but
# as this is a non-cross-platform XS module not in the core,
# we shouldn't really depend on it. See RT #24194 for detail.
# (Also, this module only supports Perl 5.6 and above).
eval "use Win32::UTCFileTime" if $^O eq 'MSWin32' && $] >= 5.006;
# If the script that is loading Module::Install is from the future,
# then make will detect this and cause it to re-run over and over
# again. This is bad. Rather than taking action to touch it (which
# is unreliable on some platforms and requires write permissions)
# for now we should catch this and refuse to run.
if ( -f $0 ) {
my $s = (stat($0))[9];
# If the modification time is only slightly in the future,
# sleep briefly to remove the problem.
my $a = $s - time;
if ( $a > 0 and $a < 5 ) { sleep 5 }
# Too far in the future, throw an error.
my $t = time;
if ( $s > $t ) { die <<"END_DIE" }
Your installer $0 has a modification time in the future ($s > $t).
This is known to create infinite loops in make.
Please correct this, then run $0 again.
END_DIE
}
# Build.PL was formerly supported, but no longer is due to excessive
# difficulty in implementing every single feature twice.
if ( $0 =~ /Build.PL$/i ) { die <<"END_DIE" }
Module::Install no longer supports Build.PL.
It was impossible to maintain duel backends, and has been deprecated.
Please remove all Build.PL files and only use the Makefile.PL installer.
END_DIE
#-------------------------------------------------------------
# To save some more typing in Module::Install installers, every...
# use inc::Module::Install
# ...also acts as an implicit use strict.
$^H |= strict::bits(qw(refs subs vars));
#-------------------------------------------------------------
unless ( -f $self->{file} ) {
foreach my $key (keys %INC) {
delete $INC{$key} if $key =~ /Module\/Install/;
}
local $^W;
require "$self->{path}/$self->{dispatch}.pm";
File::Path::mkpath("$self->{prefix}/$self->{author}");
$self->{admin} = "$self->{name}::$self->{dispatch}"->new( _top => $self );
$self->{admin}->init;
@_ = ($class, _self => $self);
goto &{"$self->{name}::import"};
}
local $^W;
*{"${who}::AUTOLOAD"} = $self->autoload;
$self->preload;
# Unregister loader and worker packages so subdirs can use them again
delete $INC{'inc/Module/Install.pm'};
delete $INC{'Module/Install.pm'};
# Save to the singleton
$MAIN = $self;
return 1;
}
sub autoload {
my $self = shift;
my $who = $self->_caller;
my $cwd = Cwd::getcwd();
my $sym = "${who}::AUTOLOAD";
$sym->{$cwd} = sub {
my $pwd = Cwd::getcwd();
if ( my $code = $sym->{$pwd} ) {
# Delegate back to parent dirs
goto &$code unless $cwd eq $pwd;
}
unless ($$sym =~ s/([^:]+)$//) {
# XXX: it looks like we can't retrieve the missing function
# via $$sym (usually $main::AUTOLOAD) in this case.
# I'm still wondering if we should slurp Makefile.PL to
# get some context or not ...
my ($package, $file, $line) = caller;
die <<"EOT";
Unknown function is found at $file line $line.
Execution of $file aborted due to runtime errors.
If you're a contributor to a project, you may need to install
some Module::Install extensions from CPAN (or other repository).
If you're a user of a module, please contact the author.
EOT
}
my $method = $1;
if ( uc($method) eq $method ) {
# Do nothing
return;
} elsif ( $method =~ /^_/ and $self->can($method) ) {
# Dispatch to the root M:I class
return $self->$method(@_);
}
# Dispatch to the appropriate plugin
unshift @_, ( $self, $1 );
goto &{$self->can('call')};
};
}
sub preload {
my $self = shift;
unless ( $self->{extensions} ) {
$self->load_extensions(
"$self->{prefix}/$self->{path}", $self
);
}
my @exts = @{$self->{extensions}};
unless ( @exts ) {
@exts = $self->{admin}->load_all_extensions;
}
my %seen;
foreach my $obj ( @exts ) {
while (my ($method, $glob) = each %{ref($obj) . '::'}) {
next unless $obj->can($method);
next if $method =~ /^_/;
next if $method eq uc($method);
$seen{$method}++;
}
}
my $who = $self->_caller;
foreach my $name ( sort keys %seen ) {
local $^W;
*{"${who}::$name"} = sub {
${"${who}::AUTOLOAD"} = "${who}::$name";
goto &{"${who}::AUTOLOAD"};
};
}
}
sub new {
my ($class, %args) = @_;
delete $INC{'FindBin.pm'};
{
# to suppress the redefine warning
local $SIG{__WARN__} = sub {};
require FindBin;
}
# ignore the prefix on extension modules built from top level.
my $base_path = Cwd::abs_path($FindBin::Bin);
unless ( Cwd::abs_path(Cwd::getcwd()) eq $base_path ) {
delete $args{prefix};
}
return $args{_self} if $args{_self};
$args{dispatch} ||= 'Admin';
$args{prefix} ||= 'inc';
$args{author} ||= ($^O eq 'VMS' ? '_author' : '.author');
$args{bundle} ||= 'inc/BUNDLES';
$args{base} ||= $base_path;
$class =~ s/^\Q$args{prefix}\E:://;
$args{name} ||= $class;
$args{version} ||= $class->VERSION;
unless ( $args{path} ) {
$args{path} = $args{name};
$args{path} =~ s!::!/!g;
}
$args{file} ||= "$args{base}/$args{prefix}/$args{path}.pm";
$args{wrote} = 0;
bless( \%args, $class );
}
sub call {
my ($self, $method) = @_;
my $obj = $self->load($method) or return;
splice(@_, 0, 2, $obj);
goto &{$obj->can($method)};
}
sub load {
my ($self, $method) = @_;
$self->load_extensions(
"$self->{prefix}/$self->{path}", $self
) unless $self->{extensions};
foreach my $obj (@{$self->{extensions}}) {
return $obj if $obj->can($method);
}
my $admin = $self->{admin} or die <<"END_DIE";
The '$method' method does not exist in the '$self->{prefix}' path!
Please remove the '$self->{prefix}' directory and run $0 again to load it.
END_DIE
my $obj = $admin->load($method, 1);
push @{$self->{extensions}}, $obj;
$obj;
}
sub load_extensions {
my ($self, $path, $top) = @_;
my $should_reload = 0;
unless ( grep { ! ref $_ and lc $_ eq lc $self->{prefix} } @INC ) {
unshift @INC, $self->{prefix};
$should_reload = 1;
}
foreach my $rv ( $self->find_extensions($path) ) {
my ($file, $pkg) = @{$rv};
next if $self->{pathnames}{$pkg};
local $@;
my $new = eval { local $^W; require $file; $pkg->can('new') };
unless ( $new ) {
warn $@ if $@;
next;
}
$self->{pathnames}{$pkg} =
$should_reload ? delete $INC{$file} : $INC{$file};
push @{$self->{extensions}}, &{$new}($pkg, _top => $top );
}
$self->{extensions} ||= [];
}
sub find_extensions {
my ($self, $path) = @_;
my @found;
File::Find::find( sub {
my $file = $File::Find::name;
return unless $file =~ m!^\Q$path\E/(.+)\.pm\Z!is;
my $subpath = $1;
return if lc($subpath) eq lc($self->{dispatch});
$file = "$self->{path}/$subpath.pm";
my $pkg = "$self->{name}::$subpath";
$pkg =~ s!/!::!g;
# If we have a mixed-case package name, assume case has been preserved
# correctly. Otherwise, root through the file to locate the case-preserved
# version of the package name.
if ( $subpath eq lc($subpath) || $subpath eq uc($subpath) ) {
my $content = Module::Install::_read($subpath . '.pm');
my $in_pod = 0;
foreach ( split /\n/, $content ) {
$in_pod = 1 if /^=\w/;
$in_pod = 0 if /^=cut/;
next if ($in_pod || /^=cut/); # skip pod text
next if /^\s*#/; # and comments
if ( m/^\s*package\s+($pkg)\s*;/i ) {
$pkg = $1;
last;
}
}
}
push @found, [ $file, $pkg ];
}, $path ) if -d $path;
@found;
}
#####################################################################
# Common Utility Functions
sub _caller {
my $depth = 0;
my $call = caller($depth);
while ( $call eq __PACKAGE__ ) {
$depth++;
$call = caller($depth);
}
return $call;
}
# Done in evals to avoid confusing Perl::MinimumVersion
eval( $] >= 5.006 ? <<'END_NEW' : <<'END_OLD' ); die $@ if $@;
sub _read {
local *FH;
open( FH, '<', $_[0] ) or die "open($_[0]): $!";
binmode FH;
my $string = do { local $/; };
close FH or die "close($_[0]): $!";
return $string;
}
END_NEW
sub _read {
local *FH;
open( FH, "< $_[0]" ) or die "open($_[0]): $!";
binmode FH;
my $string = do { local $/; };
close FH or die "close($_[0]): $!";
return $string;
}
END_OLD
sub _readperl {
my $string = Module::Install::_read($_[0]);
$string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg;
$string =~ s/(\n)\n*__(?:DATA|END)__\b.*\z/$1/s;
$string =~ s/\n\n=\w+.+?\n\n=cut\b.+?\n+/\n\n/sg;
return $string;
}
sub _readpod {
my $string = Module::Install::_read($_[0]);
$string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg;
return $string if $_[0] =~ /\.pod\z/;
$string =~ s/(^|\n=cut\b.+?\n+)[^=\s].+?\n(\n=\w+|\z)/$1$2/sg;
$string =~ s/\n*=pod\b[^\n]*\n+/\n\n/sg;
$string =~ s/\n*=cut\b[^\n]*\n+/\n\n/sg;
$string =~ s/^\n+//s;
return $string;
}
# Done in evals to avoid confusing Perl::MinimumVersion
eval( $] >= 5.006 ? <<'END_NEW' : <<'END_OLD' ); die $@ if $@;
sub _write {
local *FH;
open( FH, '>', $_[0] ) or die "open($_[0]): $!";
binmode FH;
foreach ( 1 .. $#_ ) {
print FH $_[$_] or die "print($_[0]): $!";
}
close FH or die "close($_[0]): $!";
}
END_NEW
sub _write {
local *FH;
open( FH, "> $_[0]" ) or die "open($_[0]): $!";
binmode FH;
foreach ( 1 .. $#_ ) {
print FH $_[$_] or die "print($_[0]): $!";
}
close FH or die "close($_[0]): $!";
}
END_OLD
# _version is for processing module versions (eg, 1.03_05) not
# Perl versions (eg, 5.8.1).
sub _version {
my $s = shift || 0;
my $d =()= $s =~ /(\.)/g;
if ( $d >= 2 ) {
# Normalise multipart versions
$s =~ s/(\.)(\d{1,3})/sprintf("$1%03d",$2)/eg;
}
$s =~ s/^(\d+)\.?//;
my $l = $1 || 0;
my @v = map {
$_ . '0' x (3 - length $_)
} $s =~ /(\d{1,3})\D?/g;
$l = $l . '.' . join '', @v if @v;
return $l + 0;
}
sub _cmp {
_version($_[1]) <=> _version($_[2]);
}
# Cloned from Params::Util::_CLASS
sub _CLASS {
(
defined $_[0]
and
! ref $_[0]
and
$_[0] =~ m/^[^\W\d]\w*(?:::\w+)*\z/s
) ? $_[0] : undef;
}
1;
# Copyright 2008 - 2012 Adam Kennedy.
UnixAgent-2.10.0/inc/Module/Install/ 0000775 0000000 0000000 00000000000 14323200667 0017103 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/inc/Module/Install/Base.pm 0000664 0000000 0000000 00000002257 14323200667 0020321 0 ustar 00root root 0000000 0000000 #line 1
package Module::Install::Base;
use strict 'vars';
use vars qw{$VERSION};
BEGIN {
$VERSION = '1.14';
}
# Suspend handler for "redefined" warnings
BEGIN {
my $w = $SIG{__WARN__};
$SIG{__WARN__} = sub { $w };
}
#line 42
sub new {
my $class = shift;
unless ( defined &{"${class}::call"} ) {
*{"${class}::call"} = sub { shift->_top->call(@_) };
}
unless ( defined &{"${class}::load"} ) {
*{"${class}::load"} = sub { shift->_top->load(@_) };
}
bless { @_ }, $class;
}
#line 61
sub AUTOLOAD {
local $@;
my $func = eval { shift->_top->autoload } or return;
goto &$func;
}
#line 75
sub _top {
$_[0]->{_top};
}
#line 90
sub admin {
$_[0]->_top->{admin}
or
Module::Install::Base::FakeAdmin->new;
}
#line 106
sub is_admin {
! $_[0]->admin->isa('Module::Install::Base::FakeAdmin');
}
sub DESTROY {}
package Module::Install::Base::FakeAdmin;
use vars qw{$VERSION};
BEGIN {
$VERSION = $Module::Install::Base::VERSION;
}
my $fake;
sub new {
$fake ||= bless(\@_, $_[0]);
}
sub AUTOLOAD {}
sub DESTROY {}
# Restore warning handler
BEGIN {
$SIG{__WARN__} = $SIG{__WARN__}->();
}
1;
#line 159
UnixAgent-2.10.0/inc/Module/Install/Can.pm 0000664 0000000 0000000 00000006773 14323200667 0020157 0 ustar 00root root 0000000 0000000 #line 1
package Module::Install::Can;
use strict;
use Config ();
use ExtUtils::MakeMaker ();
use Module::Install::Base ();
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
$VERSION = '1.14';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
# check if we can load some module
### Upgrade this to not have to load the module if possible
sub can_use {
my ($self, $mod, $ver) = @_;
$mod =~ s{::|\\}{/}g;
$mod .= '.pm' unless $mod =~ /\.pm$/i;
my $pkg = $mod;
$pkg =~ s{/}{::}g;
$pkg =~ s{\.pm$}{}i;
local $@;
eval { require $mod; $pkg->VERSION($ver || 0); 1 };
}
# Check if we can run some command
sub can_run {
my ($self, $cmd) = @_;
my $_cmd = $cmd;
return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd));
for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
next if $dir eq '';
require File::Spec;
my $abs = File::Spec->catfile($dir, $cmd);
return $abs if (-x $abs or $abs = MM->maybe_command($abs));
}
return;
}
# Can our C compiler environment build XS files
sub can_xs {
my $self = shift;
# Ensure we have the CBuilder module
$self->configure_requires( 'ExtUtils::CBuilder' => 0.27 );
# Do we have the configure_requires checker?
local $@;
eval "require ExtUtils::CBuilder;";
if ( $@ ) {
# They don't obey configure_requires, so it is
# someone old and delicate. Try to avoid hurting
# them by falling back to an older simpler test.
return $self->can_cc();
}
# Do we have a working C compiler
my $builder = ExtUtils::CBuilder->new(
quiet => 1,
);
unless ( $builder->have_compiler ) {
# No working C compiler
return 0;
}
# Write a C file representative of what XS becomes
require File::Temp;
my ( $FH, $tmpfile ) = File::Temp::tempfile(
"compilexs-XXXXX",
SUFFIX => '.c',
);
binmode $FH;
print $FH <<'END_C';
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
int main(int argc, char **argv) {
return 0;
}
int boot_sanexs() {
return 1;
}
END_C
close $FH;
# Can the C compiler access the same headers XS does
my @libs = ();
my $object = undef;
eval {
local $^W = 0;
$object = $builder->compile(
source => $tmpfile,
);
@libs = $builder->link(
objects => $object,
module_name => 'sanexs',
);
};
my $result = $@ ? 0 : 1;
# Clean up all the build files
foreach ( $tmpfile, $object, @libs ) {
next unless defined $_;
1 while unlink;
}
return $result;
}
# Can we locate a (the) C compiler
sub can_cc {
my $self = shift;
my @chunks = split(/ /, $Config::Config{cc}) or return;
# $Config{cc} may contain args; try to find out the program part
while (@chunks) {
return $self->can_run("@chunks") || (pop(@chunks), next);
}
return;
}
# Fix Cygwin bug on maybe_command();
if ( $^O eq 'cygwin' ) {
require ExtUtils::MM_Cygwin;
require ExtUtils::MM_Win32;
if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) {
*ExtUtils::MM_Cygwin::maybe_command = sub {
my ($self, $file) = @_;
if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) {
ExtUtils::MM_Win32->maybe_command($file);
} else {
ExtUtils::MM_Unix->maybe_command($file);
}
}
}
}
1;
__END__
#line 236
UnixAgent-2.10.0/inc/Module/Install/Fetch.pm 0000664 0000000 0000000 00000004640 14323200667 0020476 0 ustar 00root root 0000000 0000000 #line 1
package Module::Install::Fetch;
use strict;
use Module::Install::Base ();
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
$VERSION = '1.14';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
sub get_file {
my ($self, %args) = @_;
my ($scheme, $host, $path, $file) =
$args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return;
if ( $scheme eq 'http' and ! eval { require LWP::Simple; 1 } ) {
$args{url} = $args{ftp_url}
or (warn("LWP support unavailable!\n"), return);
($scheme, $host, $path, $file) =
$args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return;
}
$|++;
print "Fetching '$file' from $host... ";
unless (eval { require Socket; Socket::inet_aton($host) }) {
warn "'$host' resolve failed!\n";
return;
}
return unless $scheme eq 'ftp' or $scheme eq 'http';
require Cwd;
my $dir = Cwd::getcwd();
chdir $args{local_dir} or return if exists $args{local_dir};
if (eval { require LWP::Simple; 1 }) {
LWP::Simple::mirror($args{url}, $file);
}
elsif (eval { require Net::FTP; 1 }) { eval {
# use Net::FTP to get past firewall
my $ftp = Net::FTP->new($host, Passive => 1, Timeout => 600);
$ftp->login("anonymous", 'anonymous@example.com');
$ftp->cwd($path);
$ftp->binary;
$ftp->get($file) or (warn("$!\n"), return);
$ftp->quit;
} }
elsif (my $ftp = $self->can_run('ftp')) { eval {
# no Net::FTP, fallback to ftp.exe
require FileHandle;
my $fh = FileHandle->new;
local $SIG{CHLD} = 'IGNORE';
unless ($fh->open("|$ftp -n")) {
warn "Couldn't open ftp: $!\n";
chdir $dir; return;
}
my @dialog = split(/\n/, <<"END_FTP");
open $host
user anonymous anonymous\@example.com
cd $path
binary
get $file $file
quit
END_FTP
foreach (@dialog) { $fh->print("$_\n") }
$fh->close;
} }
else {
warn "No working 'ftp' program available!\n";
chdir $dir; return;
}
unless (-f $file) {
warn "Fetching failed: $@\n";
chdir $dir; return;
}
return if exists $args{size} and -s $file != $args{size};
system($args{run}) if exists $args{run};
unlink($file) if $args{remove};
print(((!exists $args{check_for} or -e $args{check_for})
? "done!" : "failed! ($!)"), "\n");
chdir $dir; return !$?;
}
1;
UnixAgent-2.10.0/inc/Module/Install/Include.pm 0000664 0000000 0000000 00000001045 14323200667 0021024 0 ustar 00root root 0000000 0000000 #line 1
package Module::Install::Include;
use strict;
use Module::Install::Base ();
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
$VERSION = '1.14';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
sub include {
shift()->admin->include(@_);
}
sub include_deps {
shift()->admin->include_deps(@_);
}
sub auto_include {
shift()->admin->auto_include(@_);
}
sub auto_include_deps {
shift()->admin->auto_include_deps(@_);
}
sub auto_include_dependent_dists {
shift()->admin->auto_include_dependent_dists(@_);
}
1;
UnixAgent-2.10.0/inc/Module/Install/Makefile.pm 0000664 0000000 0000000 00000032100 14323200667 0021152 0 ustar 00root root 0000000 0000000 #line 1
package Module::Install::Makefile;
use strict 'vars';
use ExtUtils::MakeMaker ();
use Module::Install::Base ();
use Fcntl qw/:flock :seek/;
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
$VERSION = '1.14';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
sub Makefile { $_[0] }
my %seen = ();
sub prompt {
shift;
# Infinite loop protection
my @c = caller();
if ( ++$seen{"$c[1]|$c[2]|$_[0]"} > 3 ) {
die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])";
}
# In automated testing or non-interactive session, always use defaults
if ( ($ENV{AUTOMATED_TESTING} or -! -t STDIN) and ! $ENV{PERL_MM_USE_DEFAULT} ) {
local $ENV{PERL_MM_USE_DEFAULT} = 1;
goto &ExtUtils::MakeMaker::prompt;
} else {
goto &ExtUtils::MakeMaker::prompt;
}
}
# Store a cleaned up version of the MakeMaker version,
# since we need to behave differently in a variety of
# ways based on the MM version.
my $makemaker = eval $ExtUtils::MakeMaker::VERSION;
# If we are passed a param, do a "newer than" comparison.
# Otherwise, just return the MakeMaker version.
sub makemaker {
( @_ < 2 or $makemaker >= eval($_[1]) ) ? $makemaker : 0
}
# Ripped from ExtUtils::MakeMaker 6.56, and slightly modified
# as we only need to know here whether the attribute is an array
# or a hash or something else (which may or may not be appendable).
my %makemaker_argtype = (
C => 'ARRAY',
CONFIG => 'ARRAY',
# CONFIGURE => 'CODE', # ignore
DIR => 'ARRAY',
DL_FUNCS => 'HASH',
DL_VARS => 'ARRAY',
EXCLUDE_EXT => 'ARRAY',
EXE_FILES => 'ARRAY',
FUNCLIST => 'ARRAY',
H => 'ARRAY',
IMPORTS => 'HASH',
INCLUDE_EXT => 'ARRAY',
LIBS => 'ARRAY', # ignore ''
MAN1PODS => 'HASH',
MAN3PODS => 'HASH',
META_ADD => 'HASH',
META_MERGE => 'HASH',
PL_FILES => 'HASH',
PM => 'HASH',
PMLIBDIRS => 'ARRAY',
PMLIBPARENTDIRS => 'ARRAY',
PREREQ_PM => 'HASH',
CONFIGURE_REQUIRES => 'HASH',
SKIP => 'ARRAY',
TYPEMAPS => 'ARRAY',
XS => 'HASH',
# VERSION => ['version',''], # ignore
# _KEEP_AFTER_FLUSH => '',
clean => 'HASH',
depend => 'HASH',
dist => 'HASH',
dynamic_lib=> 'HASH',
linkext => 'HASH',
macro => 'HASH',
postamble => 'HASH',
realclean => 'HASH',
test => 'HASH',
tool_autosplit => 'HASH',
# special cases where you can use makemaker_append
CCFLAGS => 'APPENDABLE',
DEFINE => 'APPENDABLE',
INC => 'APPENDABLE',
LDDLFLAGS => 'APPENDABLE',
LDFROM => 'APPENDABLE',
);
sub makemaker_args {
my ($self, %new_args) = @_;
my $args = ( $self->{makemaker_args} ||= {} );
foreach my $key (keys %new_args) {
if ($makemaker_argtype{$key}) {
if ($makemaker_argtype{$key} eq 'ARRAY') {
$args->{$key} = [] unless defined $args->{$key};
unless (ref $args->{$key} eq 'ARRAY') {
$args->{$key} = [$args->{$key}]
}
push @{$args->{$key}},
ref $new_args{$key} eq 'ARRAY'
? @{$new_args{$key}}
: $new_args{$key};
}
elsif ($makemaker_argtype{$key} eq 'HASH') {
$args->{$key} = {} unless defined $args->{$key};
foreach my $skey (keys %{ $new_args{$key} }) {
$args->{$key}{$skey} = $new_args{$key}{$skey};
}
}
elsif ($makemaker_argtype{$key} eq 'APPENDABLE') {
$self->makemaker_append($key => $new_args{$key});
}
}
else {
if (defined $args->{$key}) {
warn qq{MakeMaker attribute "$key" is overridden; use "makemaker_append" to append values\n};
}
$args->{$key} = $new_args{$key};
}
}
return $args;
}
# For mm args that take multiple space-separated args,
# append an argument to the current list.
sub makemaker_append {
my $self = shift;
my $name = shift;
my $args = $self->makemaker_args;
$args->{$name} = defined $args->{$name}
? join( ' ', $args->{$name}, @_ )
: join( ' ', @_ );
}
sub build_subdirs {
my $self = shift;
my $subdirs = $self->makemaker_args->{DIR} ||= [];
for my $subdir (@_) {
push @$subdirs, $subdir;
}
}
sub clean_files {
my $self = shift;
my $clean = $self->makemaker_args->{clean} ||= {};
%$clean = (
%$clean,
FILES => join ' ', grep { length $_ } ($clean->{FILES} || (), @_),
);
}
sub realclean_files {
my $self = shift;
my $realclean = $self->makemaker_args->{realclean} ||= {};
%$realclean = (
%$realclean,
FILES => join ' ', grep { length $_ } ($realclean->{FILES} || (), @_),
);
}
sub libs {
my $self = shift;
my $libs = ref $_[0] ? shift : [ shift ];
$self->makemaker_args( LIBS => $libs );
}
sub inc {
my $self = shift;
$self->makemaker_args( INC => shift );
}
sub _wanted_t {
}
sub tests_recursive {
my $self = shift;
my $dir = shift || 't';
unless ( -d $dir ) {
die "tests_recursive dir '$dir' does not exist";
}
my %tests = map { $_ => 1 } split / /, ($self->tests || '');
require File::Find;
File::Find::find(
sub { /\.t$/ and -f $_ and $tests{"$File::Find::dir/*.t"} = 1 },
$dir
);
$self->tests( join ' ', sort keys %tests );
}
sub write {
my $self = shift;
die "&Makefile->write() takes no arguments\n" if @_;
# Check the current Perl version
my $perl_version = $self->perl_version;
if ( $perl_version ) {
eval "use $perl_version; 1"
or die "ERROR: perl: Version $] is installed, "
. "but we need version >= $perl_version";
}
# Make sure we have a new enough MakeMaker
require ExtUtils::MakeMaker;
if ( $perl_version and $self->_cmp($perl_version, '5.006') >= 0 ) {
# This previous attempted to inherit the version of
# ExtUtils::MakeMaker in use by the module author, but this
# was found to be untenable as some authors build releases
# using future dev versions of EU:MM that nobody else has.
# Instead, #toolchain suggests we use 6.59 which is the most
# stable version on CPAN at time of writing and is, to quote
# ribasushi, "not terminally fucked, > and tested enough".
# TODO: We will now need to maintain this over time to push
# the version up as new versions are released.
$self->build_requires( 'ExtUtils::MakeMaker' => 6.59 );
$self->configure_requires( 'ExtUtils::MakeMaker' => 6.59 );
} else {
# Allow legacy-compatibility with 5.005 by depending on the
# most recent EU:MM that supported 5.005.
$self->build_requires( 'ExtUtils::MakeMaker' => 6.36 );
$self->configure_requires( 'ExtUtils::MakeMaker' => 6.36 );
}
# Generate the MakeMaker params
my $args = $self->makemaker_args;
$args->{DISTNAME} = $self->name;
$args->{NAME} = $self->module_name || $self->name;
$args->{NAME} =~ s/-/::/g;
$args->{VERSION} = $self->version or die <<'EOT';
ERROR: Can't determine distribution version. Please specify it
explicitly via 'version' in Makefile.PL, or set a valid $VERSION
in a module, and provide its file path via 'version_from' (or
'all_from' if you prefer) in Makefile.PL.
EOT
if ( $self->tests ) {
my @tests = split ' ', $self->tests;
my %seen;
$args->{test} = {
TESTS => (join ' ', grep {!$seen{$_}++} @tests),
};
} elsif ( $Module::Install::ExtraTests::use_extratests ) {
# Module::Install::ExtraTests doesn't set $self->tests and does its own tests via harness.
# So, just ignore our xt tests here.
} elsif ( -d 'xt' and ($Module::Install::AUTHOR or $ENV{RELEASE_TESTING}) ) {
$args->{test} = {
TESTS => join( ' ', map { "$_/*.t" } grep { -d $_ } qw{ t xt } ),
};
}
if ( $] >= 5.005 ) {
$args->{ABSTRACT} = $self->abstract;
$args->{AUTHOR} = join ', ', @{$self->author || []};
}
if ( $self->makemaker(6.10) ) {
$args->{NO_META} = 1;
#$args->{NO_MYMETA} = 1;
}
if ( $self->makemaker(6.17) and $self->sign ) {
$args->{SIGN} = 1;
}
unless ( $self->is_admin ) {
delete $args->{SIGN};
}
if ( $self->makemaker(6.31) and $self->license ) {
$args->{LICENSE} = $self->license;
}
my $prereq = ($args->{PREREQ_PM} ||= {});
%$prereq = ( %$prereq,
map { @$_ } # flatten [module => version]
map { @$_ }
grep $_,
($self->requires)
);
# Remove any reference to perl, PREREQ_PM doesn't support it
delete $args->{PREREQ_PM}->{perl};
# Merge both kinds of requires into BUILD_REQUIRES
my $build_prereq = ($args->{BUILD_REQUIRES} ||= {});
%$build_prereq = ( %$build_prereq,
map { @$_ } # flatten [module => version]
map { @$_ }
grep $_,
($self->configure_requires, $self->build_requires)
);
# Remove any reference to perl, BUILD_REQUIRES doesn't support it
delete $args->{BUILD_REQUIRES}->{perl};
# Delete bundled dists from prereq_pm, add it to Makefile DIR
my $subdirs = ($args->{DIR} || []);
if ($self->bundles) {
my %processed;
foreach my $bundle (@{ $self->bundles }) {
my ($mod_name, $dist_dir) = @$bundle;
delete $prereq->{$mod_name};
$dist_dir = File::Basename::basename($dist_dir); # dir for building this module
if (not exists $processed{$dist_dir}) {
if (-d $dist_dir) {
# List as sub-directory to be processed by make
push @$subdirs, $dist_dir;
}
# Else do nothing: the module is already present on the system
$processed{$dist_dir} = undef;
}
}
}
unless ( $self->makemaker('6.55_03') ) {
%$prereq = (%$prereq,%$build_prereq);
delete $args->{BUILD_REQUIRES};
}
if ( my $perl_version = $self->perl_version ) {
eval "use $perl_version; 1"
or die "ERROR: perl: Version $] is installed, "
. "but we need version >= $perl_version";
if ( $self->makemaker(6.48) ) {
$args->{MIN_PERL_VERSION} = $perl_version;
}
}
if ($self->installdirs) {
warn qq{old INSTALLDIRS (probably set by makemaker_args) is overridden by installdirs\n} if $args->{INSTALLDIRS};
$args->{INSTALLDIRS} = $self->installdirs;
}
my %args = map {
( $_ => $args->{$_} ) } grep {defined($args->{$_} )
} keys %$args;
my $user_preop = delete $args{dist}->{PREOP};
if ( my $preop = $self->admin->preop($user_preop) ) {
foreach my $key ( keys %$preop ) {
$args{dist}->{$key} = $preop->{$key};
}
}
my $mm = ExtUtils::MakeMaker::WriteMakefile(%args);
$self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile');
}
sub fix_up_makefile {
my $self = shift;
my $makefile_name = shift;
my $top_class = ref($self->_top) || '';
my $top_version = $self->_top->VERSION || '';
my $preamble = $self->preamble
? "# Preamble by $top_class $top_version\n"
. $self->preamble
: '';
my $postamble = "# Postamble by $top_class $top_version\n"
. ($self->postamble || '');
local *MAKEFILE;
open MAKEFILE, "+< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
eval { flock MAKEFILE, LOCK_EX };
my $makefile = do { local $/; };
$makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /;
$makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g;
$makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g;
$makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m;
$makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m;
# Module::Install will never be used to build the Core Perl
# Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks
# PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist
$makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m;
#$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m;
# Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well.
$makefile =~ s/(\"?)-I\$\(PERL_LIB\)\1//g;
# XXX - This is currently unused; not sure if it breaks other MM-users
# $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg;
seek MAKEFILE, 0, SEEK_SET;
truncate MAKEFILE, 0;
print MAKEFILE "$preamble$makefile$postamble" or die $!;
close MAKEFILE or die $!;
1;
}
sub preamble {
my ($self, $text) = @_;
$self->{preamble} = $text . $self->{preamble} if defined $text;
$self->{preamble};
}
sub postamble {
my ($self, $text) = @_;
$self->{postamble} ||= $self->admin->postamble;
$self->{postamble} .= $text if defined $text;
$self->{postamble}
}
1;
__END__
#line 544
UnixAgent-2.10.0/inc/Module/Install/Metadata.pm 0000664 0000000 0000000 00000050107 14323200667 0021164 0 ustar 00root root 0000000 0000000 #line 1
package Module::Install::Metadata;
use strict 'vars';
use Module::Install::Base ();
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
$VERSION = '1.14';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
my @boolean_keys = qw{
sign
};
my @scalar_keys = qw{
name
module_name
abstract
version
distribution_type
tests
installdirs
};
my @tuple_keys = qw{
configure_requires
build_requires
requires
recommends
bundles
resources
};
my @resource_keys = qw{
homepage
bugtracker
repository
};
my @array_keys = qw{
keywords
author
};
*authors = \&author;
sub Meta { shift }
sub Meta_BooleanKeys { @boolean_keys }
sub Meta_ScalarKeys { @scalar_keys }
sub Meta_TupleKeys { @tuple_keys }
sub Meta_ResourceKeys { @resource_keys }
sub Meta_ArrayKeys { @array_keys }
foreach my $key ( @boolean_keys ) {
*$key = sub {
my $self = shift;
if ( defined wantarray and not @_ ) {
return $self->{values}->{$key};
}
$self->{values}->{$key} = ( @_ ? $_[0] : 1 );
return $self;
};
}
foreach my $key ( @scalar_keys ) {
*$key = sub {
my $self = shift;
return $self->{values}->{$key} if defined wantarray and !@_;
$self->{values}->{$key} = shift;
return $self;
};
}
foreach my $key ( @array_keys ) {
*$key = sub {
my $self = shift;
return $self->{values}->{$key} if defined wantarray and !@_;
$self->{values}->{$key} ||= [];
push @{$self->{values}->{$key}}, @_;
return $self;
};
}
foreach my $key ( @resource_keys ) {
*$key = sub {
my $self = shift;
unless ( @_ ) {
return () unless $self->{values}->{resources};
return map { $_->[1] }
grep { $_->[0] eq $key }
@{ $self->{values}->{resources} };
}
return $self->{values}->{resources}->{$key} unless @_;
my $uri = shift or die(
"Did not provide a value to $key()"
);
$self->resources( $key => $uri );
return 1;
};
}
foreach my $key ( grep { $_ ne "resources" } @tuple_keys) {
*$key = sub {
my $self = shift;
return $self->{values}->{$key} unless @_;
my @added;
while ( @_ ) {
my $module = shift or last;
my $version = shift || 0;
push @added, [ $module, $version ];
}
push @{ $self->{values}->{$key} }, @added;
return map {@$_} @added;
};
}
# Resource handling
my %lc_resource = map { $_ => 1 } qw{
homepage
license
bugtracker
repository
};
sub resources {
my $self = shift;
while ( @_ ) {
my $name = shift or last;
my $value = shift or next;
if ( $name eq lc $name and ! $lc_resource{$name} ) {
die("Unsupported reserved lowercase resource '$name'");
}
$self->{values}->{resources} ||= [];
push @{ $self->{values}->{resources} }, [ $name, $value ];
}
$self->{values}->{resources};
}
# Aliases for build_requires that will have alternative
# meanings in some future version of META.yml.
sub test_requires { shift->build_requires(@_) }
sub install_requires { shift->build_requires(@_) }
# Aliases for installdirs options
sub install_as_core { $_[0]->installdirs('perl') }
sub install_as_cpan { $_[0]->installdirs('site') }
sub install_as_site { $_[0]->installdirs('site') }
sub install_as_vendor { $_[0]->installdirs('vendor') }
sub dynamic_config {
my $self = shift;
my $value = @_ ? shift : 1;
if ( $self->{values}->{dynamic_config} ) {
# Once dynamic we never change to static, for safety
return 0;
}
$self->{values}->{dynamic_config} = $value ? 1 : 0;
return 1;
}
# Convenience command
sub static_config {
shift->dynamic_config(0);
}
sub perl_version {
my $self = shift;
return $self->{values}->{perl_version} unless @_;
my $version = shift or die(
"Did not provide a value to perl_version()"
);
# Normalize the version
$version = $self->_perl_version($version);
# We don't support the really old versions
unless ( $version >= 5.005 ) {
die "Module::Install only supports 5.005 or newer (use ExtUtils::MakeMaker)\n";
}
$self->{values}->{perl_version} = $version;
}
sub all_from {
my ( $self, $file ) = @_;
unless ( defined($file) ) {
my $name = $self->name or die(
"all_from called with no args without setting name() first"
);
$file = join('/', 'lib', split(/-/, $name)) . '.pm';
$file =~ s{.*/}{} unless -e $file;
unless ( -e $file ) {
die("all_from cannot find $file from $name");
}
}
unless ( -f $file ) {
die("The path '$file' does not exist, or is not a file");
}
$self->{values}{all_from} = $file;
# Some methods pull from POD instead of code.
# If there is a matching .pod, use that instead
my $pod = $file;
$pod =~ s/\.pm$/.pod/i;
$pod = $file unless -e $pod;
# Pull the different values
$self->name_from($file) unless $self->name;
$self->version_from($file) unless $self->version;
$self->perl_version_from($file) unless $self->perl_version;
$self->author_from($pod) unless @{$self->author || []};
$self->license_from($pod) unless $self->license;
$self->abstract_from($pod) unless $self->abstract;
return 1;
}
sub provides {
my $self = shift;
my $provides = ( $self->{values}->{provides} ||= {} );
%$provides = (%$provides, @_) if @_;
return $provides;
}
sub auto_provides {
my $self = shift;
return $self unless $self->is_admin;
unless (-e 'MANIFEST') {
warn "Cannot deduce auto_provides without a MANIFEST, skipping\n";
return $self;
}
# Avoid spurious warnings as we are not checking manifest here.
local $SIG{__WARN__} = sub {1};
require ExtUtils::Manifest;
local *ExtUtils::Manifest::manicheck = sub { return };
require Module::Build;
my $build = Module::Build->new(
dist_name => $self->name,
dist_version => $self->version,
license => $self->license,
);
$self->provides( %{ $build->find_dist_packages || {} } );
}
sub feature {
my $self = shift;
my $name = shift;
my $features = ( $self->{values}->{features} ||= [] );
my $mods;
if ( @_ == 1 and ref( $_[0] ) ) {
# The user used ->feature like ->features by passing in the second
# argument as a reference. Accommodate for that.
$mods = $_[0];
} else {
$mods = \@_;
}
my $count = 0;
push @$features, (
$name => [
map {
ref($_) ? ( ref($_) eq 'HASH' ) ? %$_ : @$_ : $_
} @$mods
]
);
return @$features;
}
sub features {
my $self = shift;
while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) {
$self->feature( $name, @$mods );
}
return $self->{values}->{features}
? @{ $self->{values}->{features} }
: ();
}
sub no_index {
my $self = shift;
my $type = shift;
push @{ $self->{values}->{no_index}->{$type} }, @_ if $type;
return $self->{values}->{no_index};
}
sub read {
my $self = shift;
$self->include_deps( 'YAML::Tiny', 0 );
require YAML::Tiny;
my $data = YAML::Tiny::LoadFile('META.yml');
# Call methods explicitly in case user has already set some values.
while ( my ( $key, $value ) = each %$data ) {
next unless $self->can($key);
if ( ref $value eq 'HASH' ) {
while ( my ( $module, $version ) = each %$value ) {
$self->can($key)->($self, $module => $version );
}
} else {
$self->can($key)->($self, $value);
}
}
return $self;
}
sub write {
my $self = shift;
return $self unless $self->is_admin;
$self->admin->write_meta;
return $self;
}
sub version_from {
require ExtUtils::MM_Unix;
my ( $self, $file ) = @_;
$self->version( ExtUtils::MM_Unix->parse_version($file) );
# for version integrity check
$self->makemaker_args( VERSION_FROM => $file );
}
sub abstract_from {
require ExtUtils::MM_Unix;
my ( $self, $file ) = @_;
$self->abstract(
bless(
{ DISTNAME => $self->name },
'ExtUtils::MM_Unix'
)->parse_abstract($file)
);
}
# Add both distribution and module name
sub name_from {
my ($self, $file) = @_;
if (
Module::Install::_read($file) =~ m/
^ \s*
package \s*
([\w:]+)
[\s|;]*
/ixms
) {
my ($name, $module_name) = ($1, $1);
$name =~ s{::}{-}g;
$self->name($name);
unless ( $self->module_name ) {
$self->module_name($module_name);
}
} else {
die("Cannot determine name from $file\n");
}
}
sub _extract_perl_version {
if (
$_[0] =~ m/
^\s*
(?:use|require) \s*
v?
([\d_\.]+)
\s* ;
/ixms
) {
my $perl_version = $1;
$perl_version =~ s{_}{}g;
return $perl_version;
} else {
return;
}
}
sub perl_version_from {
my $self = shift;
my $perl_version=_extract_perl_version(Module::Install::_read($_[0]));
if ($perl_version) {
$self->perl_version($perl_version);
} else {
warn "Cannot determine perl version info from $_[0]\n";
return;
}
}
sub author_from {
my $self = shift;
my $content = Module::Install::_read($_[0]);
if ($content =~ m/
=head \d \s+ (?:authors?)\b \s*
([^\n]*)
|
=head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s*
.*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s*
([^\n]*)
/ixms) {
my $author = $1 || $2;
# XXX: ugly but should work anyway...
if (eval "require Pod::Escapes; 1") {
# Pod::Escapes has a mapping table.
# It's in core of perl >= 5.9.3, and should be installed
# as one of the Pod::Simple's prereqs, which is a prereq
# of Pod::Text 3.x (see also below).
$author =~ s{ E<( (\d+) | ([A-Za-z]+) )> }
{
defined $2
? chr($2)
: defined $Pod::Escapes::Name2character_number{$1}
? chr($Pod::Escapes::Name2character_number{$1})
: do {
warn "Unknown escape: E<$1>";
"E<$1>";
};
}gex;
}
elsif (eval "require Pod::Text; 1" && $Pod::Text::VERSION < 3) {
# Pod::Text < 3.0 has yet another mapping table,
# though the table name of 2.x and 1.x are different.
# (1.x is in core of Perl < 5.6, 2.x is in core of
# Perl < 5.9.3)
my $mapping = ($Pod::Text::VERSION < 2)
? \%Pod::Text::HTML_Escapes
: \%Pod::Text::ESCAPES;
$author =~ s{ E<( (\d+) | ([A-Za-z]+) )> }
{
defined $2
? chr($2)
: defined $mapping->{$1}
? $mapping->{$1}
: do {
warn "Unknown escape: E<$1>";
"E<$1>";
};
}gex;
}
else {
$author =~ s{E}{<}g;
$author =~ s{E}{>}g;
}
$self->author($author);
} else {
warn "Cannot determine author info from $_[0]\n";
}
}
#Stolen from M::B
my %license_urls = (
perl => 'http://dev.perl.org/licenses/',
apache => 'http://apache.org/licenses/LICENSE-2.0',
apache_1_1 => 'http://apache.org/licenses/LICENSE-1.1',
artistic => 'http://opensource.org/licenses/artistic-license.php',
artistic_2 => 'http://opensource.org/licenses/artistic-license-2.0.php',
lgpl => 'http://opensource.org/licenses/lgpl-license.php',
lgpl2 => 'http://opensource.org/licenses/lgpl-2.1.php',
lgpl3 => 'http://opensource.org/licenses/lgpl-3.0.html',
bsd => 'http://opensource.org/licenses/bsd-license.php',
gpl => 'http://opensource.org/licenses/gpl-license.php',
gpl2 => 'http://opensource.org/licenses/gpl-2.0.php',
gpl3 => 'http://opensource.org/licenses/gpl-3.0.html',
mit => 'http://opensource.org/licenses/mit-license.php',
mozilla => 'http://opensource.org/licenses/mozilla1.1.php',
open_source => undef,
unrestricted => undef,
restrictive => undef,
unknown => undef,
);
sub license {
my $self = shift;
return $self->{values}->{license} unless @_;
my $license = shift or die(
'Did not provide a value to license()'
);
$license = __extract_license($license) || lc $license;
$self->{values}->{license} = $license;
# Automatically fill in license URLs
if ( $license_urls{$license} ) {
$self->resources( license => $license_urls{$license} );
}
return 1;
}
sub _extract_license {
my $pod = shift;
my $matched;
return __extract_license(
($matched) = $pod =~ m/
(=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?)
(=head \d.*|=cut.*|)\z
/xms
) || __extract_license(
($matched) = $pod =~ m/
(=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?)
(=head \d.*|=cut.*|)\z
/xms
);
}
sub __extract_license {
my $license_text = shift or return;
my @phrases = (
'(?:under )?the same (?:terms|license) as (?:perl|the perl (?:\d )?programming language)' => 'perl', 1,
'(?:under )?the terms of (?:perl|the perl programming language) itself' => 'perl', 1,
'Artistic and GPL' => 'perl', 1,
'GNU general public license' => 'gpl', 1,
'GNU public license' => 'gpl', 1,
'GNU lesser general public license' => 'lgpl', 1,
'GNU lesser public license' => 'lgpl', 1,
'GNU library general public license' => 'lgpl', 1,
'GNU library public license' => 'lgpl', 1,
'GNU Free Documentation license' => 'unrestricted', 1,
'GNU Affero General Public License' => 'open_source', 1,
'(?:Free)?BSD license' => 'bsd', 1,
'Artistic license 2\.0' => 'artistic_2', 1,
'Artistic license' => 'artistic', 1,
'Apache (?:Software )?license' => 'apache', 1,
'GPL' => 'gpl', 1,
'LGPL' => 'lgpl', 1,
'BSD' => 'bsd', 1,
'Artistic' => 'artistic', 1,
'MIT' => 'mit', 1,
'Mozilla Public License' => 'mozilla', 1,
'Q Public License' => 'open_source', 1,
'OpenSSL License' => 'unrestricted', 1,
'SSLeay License' => 'unrestricted', 1,
'zlib License' => 'open_source', 1,
'proprietary' => 'proprietary', 0,
);
while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) {
$pattern =~ s#\s+#\\s+#gs;
if ( $license_text =~ /\b$pattern\b/i ) {
return $license;
}
}
return '';
}
sub license_from {
my $self = shift;
if (my $license=_extract_license(Module::Install::_read($_[0]))) {
$self->license($license);
} else {
warn "Cannot determine license info from $_[0]\n";
return 'unknown';
}
}
sub _extract_bugtracker {
my @links = $_[0] =~ m#L<(
https?\Q://rt.cpan.org/\E[^>]+|
https?\Q://github.com/\E[\w_]+/[\w_]+/issues|
https?\Q://code.google.com/p/\E[\w_\-]+/issues/list
)>#gx;
my %links;
@links{@links}=();
@links=keys %links;
return @links;
}
sub bugtracker_from {
my $self = shift;
my $content = Module::Install::_read($_[0]);
my @links = _extract_bugtracker($content);
unless ( @links ) {
warn "Cannot determine bugtracker info from $_[0]\n";
return 0;
}
if ( @links > 1 ) {
warn "Found more than one bugtracker link in $_[0]\n";
return 0;
}
# Set the bugtracker
bugtracker( $links[0] );
return 1;
}
sub requires_from {
my $self = shift;
my $content = Module::Install::_readperl($_[0]);
my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+(v?[\d\.]+)/mg;
while ( @requires ) {
my $module = shift @requires;
my $version = shift @requires;
$self->requires( $module => $version );
}
}
sub test_requires_from {
my $self = shift;
my $content = Module::Install::_readperl($_[0]);
my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+([\d\.]+)/mg;
while ( @requires ) {
my $module = shift @requires;
my $version = shift @requires;
$self->test_requires( $module => $version );
}
}
# Convert triple-part versions (eg, 5.6.1 or 5.8.9) to
# numbers (eg, 5.006001 or 5.008009).
# Also, convert double-part versions (eg, 5.8)
sub _perl_version {
my $v = $_[-1];
$v =~ s/^([1-9])\.([1-9]\d?\d?)$/sprintf("%d.%03d",$1,$2)/e;
$v =~ s/^([1-9])\.([1-9]\d?\d?)\.(0|[1-9]\d?\d?)$/sprintf("%d.%03d%03d",$1,$2,$3 || 0)/e;
$v =~ s/(\.\d\d\d)000$/$1/;
$v =~ s/_.+$//;
if ( ref($v) ) {
# Numify
$v = $v + 0;
}
return $v;
}
sub add_metadata {
my $self = shift;
my %hash = @_;
for my $key (keys %hash) {
warn "add_metadata: $key is not prefixed with 'x_'.\n" .
"Use appopriate function to add non-private metadata.\n" unless $key =~ /^x_/;
$self->{values}->{$key} = $hash{$key};
}
}
######################################################################
# MYMETA Support
sub WriteMyMeta {
die "WriteMyMeta has been deprecated";
}
sub write_mymeta_yaml {
my $self = shift;
# We need YAML::Tiny to write the MYMETA.yml file
unless ( eval { require YAML::Tiny; 1; } ) {
return 1;
}
# Generate the data
my $meta = $self->_write_mymeta_data or return 1;
# Save as the MYMETA.yml file
print "Writing MYMETA.yml\n";
YAML::Tiny::DumpFile('MYMETA.yml', $meta);
}
sub write_mymeta_json {
my $self = shift;
# We need JSON to write the MYMETA.json file
unless ( eval { require JSON; 1; } ) {
return 1;
}
# Generate the data
my $meta = $self->_write_mymeta_data or return 1;
# Save as the MYMETA.yml file
print "Writing MYMETA.json\n";
Module::Install::_write(
'MYMETA.json',
JSON->new->pretty(1)->canonical->encode($meta),
);
}
sub _write_mymeta_data {
my $self = shift;
# If there's no existing META.yml there is nothing we can do
return undef unless -f 'META.yml';
# We need Parse::CPAN::Meta to load the file
unless ( eval { require Parse::CPAN::Meta; 1; } ) {
return undef;
}
# Merge the perl version into the dependencies
my $val = $self->Meta->{values};
my $perl = delete $val->{perl_version};
if ( $perl ) {
$val->{requires} ||= [];
my $requires = $val->{requires};
# Canonize to three-dot version after Perl 5.6
if ( $perl >= 5.006 ) {
$perl =~ s{^(\d+)\.(\d\d\d)(\d*)}{join('.', $1, int($2||0), int($3||0))}e
}
unshift @$requires, [ perl => $perl ];
}
# Load the advisory META.yml file
my @yaml = Parse::CPAN::Meta::LoadFile('META.yml');
my $meta = $yaml[0];
# Overwrite the non-configure dependency hashes
delete $meta->{requires};
delete $meta->{build_requires};
delete $meta->{recommends};
if ( exists $val->{requires} ) {
$meta->{requires} = { map { @$_ } @{ $val->{requires} } };
}
if ( exists $val->{build_requires} ) {
$meta->{build_requires} = { map { @$_ } @{ $val->{build_requires} } };
}
return $meta;
}
1;
UnixAgent-2.10.0/inc/Module/Install/Scripts.pm 0000664 0000000 0000000 00000001121 14323200667 0021063 0 ustar 00root root 0000000 0000000 #line 1
package Module::Install::Scripts;
use strict 'vars';
use Module::Install::Base ();
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
$VERSION = '1.14';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
sub install_script {
my $self = shift;
my $args = $self->makemaker_args;
my $exe = $args->{EXE_FILES} ||= [];
foreach ( @_ ) {
if ( -f $_ ) {
push @$exe, $_;
} elsif ( -d 'script' and -f "script/$_" ) {
push @$exe, "script/$_";
} else {
die("Cannot find script '$_'");
}
}
}
1;
UnixAgent-2.10.0/inc/Module/Install/Win32.pm 0000664 0000000 0000000 00000003557 14323200667 0020355 0 ustar 00root root 0000000 0000000 #line 1
package Module::Install::Win32;
use strict;
use Module::Install::Base ();
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
$VERSION = '1.14';
@ISA = 'Module::Install::Base';
$ISCORE = 1;
}
# determine if the user needs nmake, and download it if needed
sub check_nmake {
my $self = shift;
$self->load('can_run');
$self->load('get_file');
require Config;
return unless (
$^O eq 'MSWin32' and
$Config::Config{make} and
$Config::Config{make} =~ /^nmake\b/i and
! $self->can_run('nmake')
);
print "The required 'nmake' executable not found, fetching it...\n";
require File::Basename;
my $rv = $self->get_file(
url => 'http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe',
ftp_url => 'ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe',
local_dir => File::Basename::dirname($^X),
size => 51928,
run => 'Nmake15.exe /o > nul',
check_for => 'Nmake.exe',
remove => 1,
);
die <<'END_MESSAGE' unless $rv;
-------------------------------------------------------------------------------
Since you are using Microsoft Windows, you will need the 'nmake' utility
before installation. It's available at:
http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe
or
ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe
Please download the file manually, save it to a directory in %PATH% (e.g.
C:\WINDOWS\COMMAND\), then launch the MS-DOS command line shell, "cd" to
that directory, and run "Nmake15.exe" from there; that will create the
'nmake.exe' file needed by this module.
You may then resume the installation process described in README.
-------------------------------------------------------------------------------
END_MESSAGE
}
1;
UnixAgent-2.10.0/inc/Module/Install/WriteAll.pm 0000664 0000000 0000000 00000002670 14323200667 0021171 0 ustar 00root root 0000000 0000000 #line 1
package Module::Install::WriteAll;
use strict;
use Module::Install::Base ();
use vars qw{$VERSION @ISA $ISCORE};
BEGIN {
$VERSION = '1.14';
@ISA = qw{Module::Install::Base};
$ISCORE = 1;
}
sub WriteAll {
my $self = shift;
my %args = (
meta => 1,
sign => 0,
inline => 0,
check_nmake => 1,
@_,
);
$self->sign(1) if $args{sign};
$self->admin->WriteAll(%args) if $self->is_admin;
$self->check_nmake if $args{check_nmake};
unless ( $self->makemaker_args->{PL_FILES} ) {
# XXX: This still may be a bit over-defensive...
unless ($self->makemaker(6.25)) {
$self->makemaker_args( PL_FILES => {} ) if -f 'Build.PL';
}
}
# Until ExtUtils::MakeMaker support MYMETA.yml, make sure
# we clean it up properly ourself.
$self->realclean_files('MYMETA.yml');
if ( $args{inline} ) {
$self->Inline->write;
} else {
$self->Makefile->write;
}
# The Makefile write process adds a couple of dependencies,
# so write the META.yml files after the Makefile.
if ( $args{meta} ) {
$self->Meta->write;
}
# Experimental support for MYMETA
if ( $ENV{X_MYMETA} ) {
if ( $ENV{X_MYMETA} eq 'JSON' ) {
$self->Meta->write_mymeta_json;
} else {
$self->Meta->write_mymeta_yaml;
}
}
return 1;
}
1;
UnixAgent-2.10.0/lib/ 0000775 0000000 0000000 00000000000 14323200667 0014245 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/ 0000775 0000000 0000000 00000000000 14323200667 0016747 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent.pm 0000664 0000000 0000000 00000036443 14323200667 0020355 0 ustar 00root root 0000000 0000000 #!/usr/bin/perl
package Ocsinventory::Agent;
use strict;
use warnings;
use POSIX ":sys_wait_h";
# THIS IS AN UGLY WORKAROUND FOR
# http://rt.cpan.org/Ticket/Display.html?id=38067
use XML::Simple;
eval {XMLout("b");};
if ($@){
no strict 'refs';
${*{"XML::SAX::"}{HASH}{'parsers'}} = sub {
return [ {
'Features' => {
'http://xml.org/sax/features/namespaces' => '1'
},
'Name' => 'XML::SAX::PurePerl'
}]
};
}
# END OF THE UGLY FIX!
require Exporter;
use Ocsinventory::Logger;
use Ocsinventory::Agent::XML::Inventory;
use Ocsinventory::Agent::XML::Prolog;
use Ocsinventory::Agent::Network;
use Ocsinventory::Agent::Backend;
use Ocsinventory::Agent::AccountConfig;
use Ocsinventory::Agent::AccountInfo;
use Ocsinventory::Agent::Config;
use Ocsinventory::Agent::Hooks;
#use Ocsinventory::Agent::Pid;
use Ocsinventory::Agent::Common;
sub run {
# Load setting from the config file
my $config = new Ocsinventory::Agent::Config;
#$params->{$_} = $config->{$_} foreach (keys %$config);
$ENV{LC_ALL} = 'C'; # Turn off localised output for commands
$ENV{LANG} = 'C'; # Turn off localised output for commands
#####################################
################ MAIN ###############
#####################################
############################
#### CLI parameters ########
############################
$config->loadUserParams();
# I close STDERR to avoid error message during the module execution
# at the beginning I was doing shell redirection:
# my @ret = `cmd 2> /dev/null`;
# but this syntax is not supported on (at least) FreeBSD and Solaris
# c.f: http://www.perlmonks.org/?node_id=571072
#my $tmp;
#open ($tmp, ">&STDERR");
#$params->{"savedstderr"} = $tmp;
#if($params->{debug}) {
# $params->{verbose} = 1;
#} else {
# close(STDERR);
#}
if ($config->{config}{logfile}) {
$config->{config}{logger} = 'File';
}
my $logger = new Ocsinventory::Logger ({
config => $config->{config}
});
my $common = new Ocsinventory::Agent::Common({
logger => $logger,
config => $config->{config},
});
# $< == $REAL_USER_ID
if ( $< ne '0' ) {
$logger->info("You should run this program as super-user.");
}
if (not $config->{config}{scanhomedirs}) {
$logger->debug("--scan-homedirs missing. Don't scan user directories");
}
if ($config->{config}{nosoftware}) {
$config->{config}{nosoftware} = 1
}
# desactivate local mode even if it is set in config file or command line
if (defined($config->{config}{nolocal})) {
undef $config->{config}{'local'};
}
# TODO put that in Ocsinventory::Agent::Config
if (!$config->{config}{'stdout'} && !$config->{config}{'local'} && $config->{config}{server} !~ /^http(|s):\/\//) {
$logger->debug("the --server passed doesn't have a protocol, assume http as default");
$config->{config}{server} = "http://".$config->{config}{server}.'/ocsinventory';
}
######################## Objects initilisation ###############################################################
# The agent can contact different servers. Each server accountconfig is
# stored in a specific file:
if (!recMkdir ($config->{config}{basevardir})) {
if (! -d $ENV{HOME}."/.ocsinventory/var") {
$logger->info("Failed to create ".$config->{config}{basevardir}." directory: $!. ".
"I'm going to use the home directory instead (~/.ocsinventory/var).");
}
$config->{config}{basevardir} = $ENV{HOME}."/.ocsinventory/var";
if (!recMkdir ($config->{config}{basevardir})) {
$logger->error("Failed to create ".$config->{config}{basedir}." directory: $!".
"The HOSTID will not be written on the harddrive. You may have duplicated ".
"entry of this computer in your OCS database");
}
$logger->debug("var files are stored in ".$config->{config}{basevardir});
}
if (defined($config->{config}{server}) && $config->{config}{server}) {
my $dir = $config->{config}{server};
$dir =~ s/\//_/g;
$config->{config}{vardir} = $config->{config}{basevardir}."/".$dir;
if (defined ($config->{config}{local}) && $config->{config}{local}) {
$logger->debug ("--server ignored since you also use --local");
$config->{config}{server} = undef;
}
} elsif (defined($config->{config}{local}) && $config->{config}{local}) {
$config->{config}{vardir} = $config->{config}{basevardir}."/__LOCAL__";
} else {
$logger->error("You must set either --server or --local");
}
if (!recMkdir ($config->{config}{vardir})) {
$logger->error("Failed to create ".$config->{config}{vardir}." directory: $!");
}
if (-d $config->{config}{vardir}) {
$config->{config}{accountconfig} = $config->{config}{vardir}."/ocsinv.conf";
$config->{config}{accountinfofile} = $config->{config}{vardir}."/ocsinv.adm";
$config->{config}{last_statefile} = $config->{config}{vardir}."/last_state";
$config->{config}{next_timefile} = $config->{config}{vardir}."/next_timefile";
}
# Setting SSL CA file path if not set in configuration
unless ($config->{config}{ca}) {
# use server specific cacert.pem if it exists
$config->{config}{ca} = $config->{config}{vardir}.'/cacert.pem';
# if no server specific cacert.pem, look for a bundle in our config dir
unless (-e $config->{config}{vardir}.'/cacert.pem') {
foreach (@{$config->{config}{etcdir}}) {
if (-e $_.'/ocsinventory-agent-cacert.pem') {
$config->{config}{ca} = $_.'/ocsinventory-agent-cacert.pem';
last;
}
}
}
}
################################################################################################################
########################## load CFG files ######################################################################
my $accountconfig = new Ocsinventory::Agent::AccountConfig({
logger => $logger,
config => $config->{config},
});
my $srv = $accountconfig->get('OCSFSERVER');
$config->{config}{server} = $srv if $srv;
$config->{config}{deviceid} = $accountconfig->get('DEVICEID');
# Should I create a new deviceID?
chomp(my $hostname = `uname -n| cut -d . -f 1`);
if ((!$config->{config}{deviceid}) || $config->{config}{deviceid} !~ /\Q$hostname\E-(?:\d{4})(?:-\d{2}){5}/) {
my ($YEAR, $MONTH , $DAY, $HOUR, $MIN, $SEC) = (localtime(time))[5,4,3,2,1,0];
$config->{config}{old_deviceid} = $config->{config}{deviceid};
$config->{config}{deviceid} =sprintf "%s-%02d-%02d-%02d-%02d-%02d-%02d", $hostname, ($YEAR+1900), ($MONTH+1), $DAY, $HOUR, $MIN, $SEC;
$accountconfig->set('DEVICEID',$config->{config}{deviceid});
}
my $accountinfo = new Ocsinventory::Agent::AccountInfo({
logger => $logger,
# TODOparams => $params,
config => $config->{config},
common => $common,
});
# --lazy
if ($config->{config}{lazy}) {
my $nexttime = (stat($config->{config}{next_timefile}))[9];
if ($nexttime && $nexttime > time) {
$logger->info("[Lazy] Must wait until ".localtime($nexttime)." exiting...");
exit 0;
}
}
if ($config->{config}{daemon}) {
$logger->debug("Time to call Proc::Daemon");
eval { require Proc::Daemon; };
if ($@) {
print "Can't load Proc::Daemon. Is the module installed?";
exit 1;
}
Proc::Daemon::Init();
$logger->debug("Daemon started");
if (isAgentAlreadyRunning({
logger => $logger,
})) {
$logger->debug("An agent is already runnnig, exiting...");
exit 1;
}
}
$logger->debug("OCS Agent initialised");
################# Now we can create a context hash #########################################################
my $context = {
installpath => $config->{config}->{vardir},
servername => $config->{config}->{server},
authuser => $config->{config}->{user},
authpwd => $config->{config}->{password},
authrealm => $config->{config}->{realm},
deviceid => $config->{config}->{deviceid},
version => $config->{VERSION},
config => $config->{config},
accountconfig => $accountconfig,
accountinfo => $accountinfo,
logger => $logger,
common => $common,
# OCS_AGENT_CMDL => "TOTO", # TODO cmd line parameter changed with the unified agent
};
################################# HERE WE GO !!! ###################################################
while (1) {
my $exitcode = 0;
my $wait;
my $child;
if ($config->{config}{daemon} || $config->{config}{wait}) {
my $serverdelay;
if(($config->{config}{wait} eq 'server') || ($config->{config}{wait}!~/^\d+$/)){
$serverdelay = $accountconfig->get('PROLOG_FREQ')*3600;
} else {
$serverdelay = $config->{config}{wait};
}
$wait = int rand($serverdelay?$serverdelay:$config->{config}{delaytime});
$logger->info("Going to sleep for $wait second(s)");
sleep ($wait);
}
# Create an hook object to use handlers of modules.
my $hooks = new Ocsinventory::Agent::Hooks($context);
# Using start_handler hook
$hooks->run({name => 'start_handler'});
#################### Local Mode #######################
if ($config->{config}{stdout} || $config->{config}{local}) {
# TODO, avoid to create Backend at two different places
my $backend = new Ocsinventory::Agent::Backend ({
context => $context,
});
my $inventory = new Ocsinventory::Agent::XML::Inventory ({
# TODO, check if the accoun{info,config} are needed in localmode
backend => $backend,
context => $context,
});
# Launching inventory
$inventory->initialise();
# Using inventory_writer hook
$hooks->run({name => 'inventory_handler'}, $inventory);
if ($config->{config}{stdout}) {
$inventory->printXML();
} elsif ($config->{config}{local}) {
$inventory->writeXML();
}
} else {
############ I've to contact the server ########################"
my $network = new Ocsinventory::Agent::Network ({
accountconfig => $accountconfig,
accountinfo => $accountinfo,
logger => $logger,
config => $config->{config},
common => $common,
});
# Adding the network object in $context
$context->{network}= $network;
my $sendInventory = 1;
my $httpresp;
my $prologresp;
if (!$config->{config}{force}) {
my $prolog = new Ocsinventory::Agent::XML::Prolog({
context => $context,
});
# Using prolog_writer hook
$hooks->run({name => 'prolog_writer'}, $prolog);
# Formatting the XML
my $prologXML = $prolog->getContent();
$httpresp = $network->sendXML({message => $prologXML});
$prologresp = $network->getXMLResp($httpresp,'Prolog');
if ($prologresp) {
# Using prolog_reader hook
$hooks->run({name => 'prolog_reader'}, $prologresp->getRawXML());
if (!$prologresp->isInventoryAsked()) {
$sendInventory = 0;
}
} else { # Failed to reach the server
if ($config->{config}{lazy}) {
# To avoid flooding a heavy loaded server
my $previousPrologFreq;
if (!($previousPrologFreq = $accountconfig->get('PROLOG_FREQ'))){
$previousPrologFreq = $config->{config}{delaytime};
$logger->info("No previous PROLOG_FREQ found - using fallback delay(".$config->{config}{delaytime}." seconds)");
} else {
$logger->info("Previous PROLOG_FREQ found ($previousPrologFreq)");
$previousPrologFreq = $previousPrologFreq*3600;
}
my $time = time + $previousPrologFreq;
utime $time,$time,$config->{config}{next_timefile};
}
exit 1 unless $config->{config}{daemon};
$sendInventory = 0;
}
}
if (!$sendInventory) {
$logger->info("Don't send the inventory");
} else { # Send the inventory!
my $backend = new Ocsinventory::Agent::Backend ({
prologresp => $prologresp,
context => $context,
});
my $inventory = new Ocsinventory::Agent::XML::Inventory ({
# TODO, check if the accoun{info,config} are needed in localmode
backend => $backend,
context => $context,
});
# Launching inventory
$inventory->initialise();
# Using inventory_writer hook
$hooks->run({name => 'inventory_handler'}, $inventory);
# Formatting the XML
my $inventoryXML = $inventory->getContent();
# Sending Inventory
$httpresp = $network->sendXML({message => $inventoryXML});
if (my $invresp = $network->getXMLResp($httpresp,'Inventory')) {
$inventory->saveLastState();
} else {
exit (1) unless $config->{config}{daemon};
}
}
}
# Using end_handler_hook
$hooks->run({name => 'end_handler'});
# Avoid zombie process
if ($^O ne 'darwin'){
do {
$child = waitpid(-1, WNOHANG);
} while $child > 0;
} else {
waitpid(-1, 0);
}
exit (0) unless $config->{config}{daemon};
}
}
##########################################
############Functions#####################
##########################################
sub recMkdir {
my $dir = shift;
my @t = split /\//, $dir;
shift @t;
return unless @t;
my $t;
foreach (@t) {
$t .= '/'.$_;
if ((!-d $t) && (!mkdir $t)) {
return;
}
}
1;
}
sub isAgentAlreadyRunning {
my $params = shift;
my $logger = $params->{logger};
# TODO add a workaround if Proc::PID::File is not installed
eval { require Proc::PID::File; };
if(!$@) {
$logger->debug('Proc::PID::File available, checking for pid file');
if (Proc::PID::File->running()) {
$logger->debug('parent process already exists');
return 1;
}
}
return 0;
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/ 0000775 0000000 0000000 00000000000 14323200667 0020005 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/AccountConfig.pm 0000664 0000000 0000000 00000003614 14323200667 0023071 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::AccountConfig;
use strict;
use warnings;
# AccountConfig read and write the setting for the client given by the server
# This file will be overwrite and is not designed to be changed by the user
# DESPITE ITS NAME, ACCOUNTCONFIG IS NOT A CONFIG FILE!
sub new {
my (undef,$params) = @_;
my $self = {};
bless $self;
$self->{config} = $params->{config};
my $logger = $self->{logger} = $params->{logger};
# Configuration reading
$self->{xml} = {};
if ($self->{config}->{accountconfig}) {
if (! -f $self->{config}->{accountconfig}) {
$logger->debug ('accountconfig file: `'. $self->{config}->{accountconfig}.
" doesn't exist. I create an empty one");
$self->write();
} else {
eval {
$self->{xml} = XML::Simple::XMLin(
$self->{config}->{accountconfig},
SuppressEmpty => undef
);
};
}
}
$self;
}
sub get {
my ($self, $name) = @_;
my $logger = $self->{logger};
return $self->{xml}->{$name} if $name;
return $self->{xml};
}
sub set {
my ($self, $name, $value) = @_;
my $logger = $self->{logger};
$self->{xml}->{$name} = $value;
$self->write(); # save the change
}
sub write {
my ($self, $args) = @_;
my $logger = $self->{logger};
return unless $self->{config}->{accountconfig};
my $xml = XML::Simple::XMLout( $self->{xml} , RootName => 'CONF',
NoAttr => 1 );
my $fault;
if (!open CONF, ">".$self->{config}->{accountconfig}) {
$fault = 1;
} else {
print CONF $xml;
$fault = 1 if (!close CONF);
}
if (!$fault) {
$logger->debug ("ocsinv.conf updated successfully");
} else {
$logger->error ("Can't save setting change in `".$self->{config}->{accountconfig}."'");
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/AccountInfo.pm 0000664 0000000 0000000 00000007254 14323200667 0022563 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::AccountInfo;
use strict;
use warnings;
use Encode qw(decode);
sub new {
my (undef,$params) = @_;
my $self = {};
bless $self;
$self->{config} = $params->{config};
$self->{logger} = $params->{logger};
$self->{common} = $params->{common};
my $logger = $self->{logger} = $params->{logger};
if ($self->{config}->{accountinfofile}) {
$logger->debug ('Accountinfo file: '. $self->{config}->{accountinfofile});
if (! -f $self->{config}->{accountinfofile}) {
$logger->info ("Accountinfo file doesn't exist. I create an empty one.");
$self->writeAccountInfoFile();
} else {
my $xmladm;
eval {
$xmladm = $self->{common}->readXml($self->{config}->{accountinfofile}, [ 'ACCOUNTINFO' ]);
};
if ($xmladm && exists($xmladm->{ACCOUNTINFO})) {
# Store the XML content in a local HASH
for(@{$xmladm->{ACCOUNTINFO}}){
if (!$_->{KEYNAME}) {
$logger->debug ("Incorrect KEYNAME in ACCOUNTINFO");
}
$self->{accountinfo}{ $_->{KEYNAME} } = $_->{KEYVALUE};
}
}
}
} else {
$logger->debug("No accountinfo file defined");
}
if ($self->{config}->{tag}) {
if ($self->{accountinfo}->{TAG}) {
$logger->debug("A TAG seems to already exist in the ocsinv.adm file. ".
"The -t parameter will be ignored. Don't forget that the TAG value ".
"will be ignored by the server unless it has OCS_OPT_ACCEPT_TAG_UPDATE_FROM_CLIENT=1.");
} else {
$self->{accountinfo}->{TAG} = decode('UTF-8', $self->{config}->{tag});
}
}
$self; #Because we have already blessed the object
}
# Add accountinfo stuff to an inventory
sub setAccountInfo {
my $self = shift;
my $inventory = shift;
#my $ai = $self->getAll();
$self->{xmlroot}{'CONTENT'}{ACCOUNTINFO} = [];
my $ai = $self->{accountinfo};
return unless $ai;
foreach (keys %$ai) {
push @{$inventory->{xmlroot}{'CONTENT'}{ACCOUNTINFO}}, {
KEYNAME => [$_],
KEYVALUE => [$ai->{$_}],
};
}
}
sub writeAccountInfoFile {
my ($self, $ref) = @_;
my $logger = $self->{logger};
my $content;
$content->{ACCOUNTINFO} = [];
#We clear accountinfo to store the new one
undef $self->{accountinfo};
#We get values sent by server
if (ref ($ref) =~ /^ARRAY$/) {
foreach (@$ref) {
$self->{accountinfo}->{$_->{KEYNAME}} = $_->{KEYVALUE} if defined ($_->{KEYNAME}) && defined ($_->{KEYVALUE});
}
} elsif (ref ($ref) =~ /^HASH$/) {
$self->{accountinfo}->{$ref->{KEYNAME}} = $ref->{KEYVALUE} if defined ($ref->{KEYNAME}) && defined ($ref->{KEYVALUE});
} else {
$logger->debug ("Invalid parameter while writing accountinfo file");
}
#We feed our XML for accountinfo file
foreach (keys %{$self->{accountinfo}}) {
push @{$content->{ACCOUNTINFO}}, {KEYNAME => [$_], KEYVALUE =>
[$self->{accountinfo}{$_}]};
}
my $xml=XML::Simple::XMLout($content, RootName => 'ADM', XMLDecl=> '');
#We write accountinfo file
my $fault;
if (!open ADM, ">".$self->{config}->{accountinfofile}) {
$fault = 1;
} else {
print ADM $xml;
$fault = 1 unless close ADM;
}
if (!$fault) {
$logger->debug ("Account info updated successfully");
} else {
$logger->error ("Can't save account info in `".
$self->{config}->{accountinfofile});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend.pm 0000664 0000000 0000000 00000027423 14323200667 0021702 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend;
use strict;
no strict 'refs';
use warnings;
#use ExtUtils::Installed;
sub new {
my (undef, $params) = @_;
my $self = {};
$self->{accountconfig} = $params->{context}->{accountconfig};
$self->{accountinfo} = $params->{context}->{accountinfo};
$self->{config} = $params->{context}->{config};
$self->{inventory} = $params->{inventory};
$self->{common} = $params->{context}->{common};
my $logger = $self->{logger} = $params->{context}->{logger};
$self->{prologresp} = $params->{prologresp};
$self->{modules} = {};
$self->{backendSharedFuncs} = {
can_run => sub {
my $binary = shift;
my $calling_namespace = caller(0);
chomp(my $binpath=`which $binary 2>/dev/null`);
return unless -x $binpath;
$self->{logger}->debug(" - $binary found");
1
},
can_load => sub {
my $module = shift;
my $calling_namespace = caller(0);
eval "package $calling_namespace; use $module;";
# print STDERR "$module not loaded in $calling_namespace! $!: $@\n" if $@;
return if $@;
$self->{logger}->debug(" - $module loaded");
# print STDERR "$module loaded in $calling_namespace!\n";
1;
},
can_read => sub {
my $file = shift;
return unless -r $file;
$self->{logger}->debug(" - $file can be read");
1;
},
runcmd => sub {
my $cmd = shift;
return unless $cmd;
# $self->{logger}->debug(" - run $cmd");
return `$cmd`;
}
};
bless $self;
}
sub initModList {
my $self = shift;
my $logger = $self->{logger};
my $config = $self->{config};
my @dirToScan;
my @installed_mods;
my @installed_files;
# This is a workaround for PAR::Packer. Since it resets @INC
# I can't find the backend modules to load dynamically. So
# I prepare a list and include it.
eval "use Ocsinventory::Agent::Backend::ModuleToLoad;";
if (!$@) {
$logger->debug("use Ocsinventory::Agent::Backend::ModuleToLoad to get the modules ".
"to load. This should not append unless you use the standalone agent built with ".
"PAR::Packer (pp)");
push @installed_mods, @Ocsinventory::Agent::Backend::ModuleToLoad::list;
}
if ($config->{devlib}) {
# devlib enable, I only search for backend module in ./lib
push (@dirToScan, './lib');
} else {
# my ($inst) = ExtUtils::Installed->new();
# eval {@installed_files =
# $inst->files('Ocsinventory')};
# ExtUtils::Installed is nice but it needs properly installed package with
# .packlist
# This is a workaround for 'invalide' installations...
foreach (@INC) {
next if ! -d || (-l && -d readlink) || /^(\.|lib)$/;
push @dirToScan, $_;
}
}
if (@dirToScan) {
eval {require File::Find};
if ($@) {
$logger->debug("Failed to load File::Find");
} else {
# here I need to use $d to avoid a bug with AIX 5.2's perl 5.8.0. It
# changes the @INC content if i use $_ directly
# thanks to @rgs on irc.perl.org
File::Find::find(
{
wanted => sub {
push @installed_files, $File::Find::name if $File::Find::name =~ /Ocsinventory\/Agent\/Backend\/.*\.pm$/;
},
follow => 1,
follow_skip => 2
}
, @dirToScan);
}
}
foreach my $file (@installed_files) {
my $t = $file;
next unless $t =~ s!.*?(Ocsinventory/Agent/Backend/)(.*?)\.pm$!$1$2!;
my $m = join ('::', split /\//, $t);
push @installed_mods, $m;
}
if (!@installed_mods) {
$logger->info("ZERO backend module found! Is Ocsinventory-Agent ".
"correctly installed? Use the --devlib flag if you want to run the agent ".
"directly from the source directory.")
}
foreach my $m (@installed_mods) {
my @runAfter;
my @runMeIfTheseChecksFailed;
my $enable = 1;
if (exists ($self->{modules}->{$m}->{name})) {
$logger->debug($m." already loaded.");
next;
}
eval "use $m;";
if ($@) {
$logger->debug ("Failed to load $m: $@");
$enable = 0;
}
my $package = $m."::";
# Load in the module the backendSharedFuncs
# foreach my $func (keys %{$self->{backendSharedFuncs}}) {
# $package->{$func} = $self->{backendSharedFuncs}->{$func};
# }
$self->{modules}->{$m}->{name} = $m;
$self->{modules}->{$m}->{done} = 0;
$self->{modules}->{$m}->{inUse} = 0;
$self->{modules}->{$m}->{enable} = $enable;
$self->{modules}->{$m}->{checkFunc} = $package->{"check"};
$self->{modules}->{$m}->{runAfter} = $package->{'runAfter'};
$self->{modules}->{$m}->{runMeIfTheseChecksFailed} = $package->{'runMeIfTheseChecksFailed'};
# $self->{modules}->{$m}->{replace} = \@replace;
$self->{modules}->{$m}->{runFunc} = $package->{'run'};
$self->{modules}->{$m}->{mem} = {};
# Load the Storable object is existing or return undef
$self->{modules}->{$m}->{storage} = $self->retrieveStorage($m);
}
# the sort is just for the presentation
foreach my $m (sort keys %{$self->{modules}}) {
next unless $self->{modules}->{$m}->{checkFunc};
# find modules to disable and their submodules
if($self->{modules}->{$m}->{enable} &&
!$self->runWithTimeout(
$m,
$self->{modules}->{$m}->{checkFunc},
{
accountconfig => $self->{accountconfig},
accountinfo => $self->{accountinfo},
config => $self->{config},
inventory => $self->{inventory},
logger => $self->{logger},
params => $self->{params}, # Compatibiliy with agent 0.0.10 <=
prologresp => $self->{prologresp},
mem => $self->{modules}->{$m}->{mem},
storage => $self->{modules}->{$m}->{storage},
common => $self->{common},
})) {
$logger->debug ($m." ignored");
foreach (keys %{$self->{modules}}) {
$self->{modules}->{$_}->{enable} = 0 if /^$m($|::)/;
}
}
# add submodule in the runAfter array
my $t;
foreach (split /::/,$m) {
$t .= "::" if $t;
$t .= $_;
if (exists $self->{modules}->{$t} && $m ne $t) {
push @{$self->{modules}->{$m}->{runAfter}}, \%{$self->{modules}->{$t}}
}
}
}
# Remove the runMeIfTheseChecksFailed if needed
foreach my $m (sort keys %{$self->{modules}}) {
next unless $self->{modules}->{$m}->{enable};
next unless $self->{modules}->{$m}->{runMeIfTheseChecksFailed};
foreach my $condmod (@{${$self->{modules}->{$m}->{runMeIfTheseChecksFailed}}}) {
if ($self->{modules}->{$condmod}->{enable}) {
foreach (keys %{$self->{modules}}) {
next unless /^$m($|::)/ && $self->{modules}->{$_}->{enable};
$self->{modules}->{$_}->{enable} = 0;
$logger->debug ("$_ disabled because of a 'runMeIfTheseChecksFailed' in '$m'\n");
}
}
}
}
}
sub runMod {
my ($self, $params) = @_;
my $logger = $self->{logger};
my $m = $params->{modname};
my $common = $params->{common};
return if (!$self->{modules}->{$m}->{enable});
return if ($self->{modules}->{$m}->{done});
$self->{modules}->{$m}->{inUse} = 1; # lock the module
# first I run its "runAfter"
foreach (@{$self->{modules}->{$m}->{runAfter}}) {
if (!$_->{name}) {
# The name is defined during module initialisation so if I
# can't read it, I can suppose it had not been initialised.
$logger->fault ("Module `$m' need to be runAfter a module not found.".
"Please fix its runAfter entry or add the module.");
}
if ($_->{inUse}) {
# In use 'lock' is taken during the mod execution. If a module
# need a module also in use, we have provable an issue :).
$logger->fault ("Circular dependency hell with $m and $_->{name}");
}
$self->runMod({
common => $common,
modname => $_->{name},
});
}
$logger->debug ("Running $m");
if ($self->{modules}->{$m}->{runFunc}) {
$self->runWithTimeout(
$m,
$self->{modules}->{$m}->{runFunc},
{
accountconfig => $self->{accountconfig},
accountinfo => $self->{accountinfo},
config => $self->{config},
common => $common,
logger => $logger,
params => $self->{params}, # For compat with agent 0.0.10 <=
prologresp => $self->{prologresp},
mem => $self->{modules}->{$m}->{mem},
storage => $self->{modules}->{$m}->{storage},
common => $self->{common},
}
);
} else {
$logger->debug("$m has no run() function -> ignored");
}
$self->{modules}->{$m}->{done} = 1;
$self->{modules}->{$m}->{inUse} = 0; # unlock the module
$self->saveStorage($m, $self->{modules}->{$m}->{storage});
}
sub feedInventory {
my ($self, $params) = @_;
my $common = $self->{common};
my $inventory;
if ($params->{inventory}) {
$inventory = $params->{inventory};
}
if (!keys %{$self->{modules}}) {
$self->initModList();
}
my $begin = time();
foreach my $m (sort keys %{$self->{modules}}) {
die ">$m Houston!!!" unless $m;
$self->runMod ({
common => $common,
modname => $m,
});
}
# Execution time
# $common->setHardware({ETIME => time() - $begin});
$inventory->{xmlroot}->{CONTENT} = $common->{xmltags};
}
sub retrieveStorage {
my ($self, $m) = @_;
my $logger = $self->{logger};
my $storagefile = $self->{config}->{vardir}."/$m.storage";
if (!exists &retrieve) {
eval "use Storable;";
if ($@) {
$logger->debug("Storable.pm is not available, can't load Backend module data");
return;
}
}
return (-f $storagefile)?retrieve($storagefile):{};
}
sub saveStorage {
my ($self, $m, $data) = @_;
my $logger = $self->{logger};
# Perl 5.6 doesn't provide Storable.pm
if (!exists &store) {
eval "use Storable;";
if ($@) {
$logger->debug("Storable.pm is not available, can't save Backend module data");
return;
}
}
my $storagefile = $self->{config}->{vardir}."/$m.storage";
if ($data && keys (%$data)>0) {
store ($data, $storagefile) or die;
} elsif (-f $storagefile) {
unlink $storagefile;
}
}
sub runWithTimeout {
my ($self, $m, $func, $params) = @_;
my $logger = $self->{logger};
my $ret;
eval {
local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n require
my $timeout = $params->{config}{backendCollectTimeout};
alarm $timeout;
$ret = &{$func}($params);
};
alarm 0;
if ($@) {
if ($@ ne "alarm\n") {
$logger->debug("runWithTimeout(): unexpected error: $@");
} else {
$logger->debug("$m killed by a timeout.");
return;
}
} else {
return $ret;
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/ 0000775 0000000 0000000 00000000000 14323200667 0021334 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/AccessLog.pm 0000664 0000000 0000000 00000000630 14323200667 0023534 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::AccessLog;
sub run {
my $params = shift;
my $common = $params->{common};
my ($YEAR, $MONTH , $DAY, $HOUR, $MIN, $SEC) = (localtime (time))[5,4,3,2,1,0];
my $date=sprintf "%02d-%02d-%02d %02d:%02d:%02d", ($YEAR+1900), ($MONTH+1), $DAY, $HOUR, $MIN, $SEC;
$common->setAccessLog ({
USERID => 'N/A',
LOGDATE => $date
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/DeviceID.pm 0000664 0000000 0000000 00000000755 14323200667 0023315 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::DeviceID;
# Initialise the DeviceID. In fact this value is a bit specific since
# it generates in the main script.
sub run {
my $params = shift;
my $common = $params->{common};
my $config = $params->{config};
my $UsersLoggedIn = join "/", keys %user;
if ($config->{old_deviceid}) {
$common->setHardware({ OLD_DEVICEID => $config->{old_deviceid} });
}
$common->setHardware({ DEVICEID => $config->{deviceid} });
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/IpDiscover.pm 0000664 0000000 0000000 00000000423 14323200667 0023740 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::IpDiscover;
use strict;
sub check {
my $params = shift;
my $prologresp = $params->{prologresp};
my $mem = $params->{mem};
return unless ($prologresp && $prologresp->getOptionsInfoByName("IPDISCOVER"));
1;
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/IpDiscover/ 0000775 0000000 0000000 00000000000 14323200667 0023403 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/IpDiscover/IpDiscover.pm 0000664 0000000 0000000 00000004163 14323200667 0026014 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::IpDiscover::IpDiscover;
use strict;
use warnings;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run ("ipdiscover");
}
sub run {
my $params = shift;
my $common = $params->{common};
my $prologresp = $params->{prologresp};
my $logger = $params->{logger};
# Let's find network interfaces and call ipdiscover on it
my $options = $prologresp->getOptionsInfoByName("IPDISCOVER");
my $ipdisc_lat;
my $network;
if ($options->[0] && exists($options->[0]->{IPDISC_LAT}) && $options->[0]->{IPDISC_LAT}) {
$ipdisc_lat = $options->[0]->{IPDISC_LAT};
}
if ($options->[0] && exists($options->[0]->{content})) {
$network = $options->[0]->{content};
} else {
return;
}
$logger->debug("Scanning the $network network");
my $legacymode;
if ( `ipdiscover` =~ /binary ver. (\d+)/ ){
if (!($1>3)) {
$legacymode = 1;
$logger->debug("ipdiscover ver.$1: legacymode");
}
}
my $ifname;
if ($common->can_run("ip")) {
foreach (`ip route`) {
if (/^default via (\d+\d.\d+\.\d+\.\d+) dev (\S+).*/) {
if ($network = $1 ){
$ifname = $2;
last;
}
}
}
} elsif ($common->can_run("route")){
foreach (`route -n`) {
if (/^(\d+\.\d+\.\d+\.\d+).*?\s(\S+)$/) {
if ($network eq $1) {
$ifname = $2;
last;
} elsif (!$ifname && $1 eq "0.0.0.0") {
$ifname = $2;
}
}
}
}
if ($ifname) {
my $cmd = "ipdiscover $ifname ";
$cmd .= $ipdisc_lat if ($ipdisc_lat && !$legacymode);
foreach (`$cmd`) {
if (/([\d\.]*)<\/I>([\w\:]*)<\/M>(\S*)<\/N><\/H>/) {
$common->addIpDiscoverEntry({
IPADDRESS => $1,
MACADDR => $2,
NAME => $3
});
}
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/IpDiscover/Nmap.pm 0000664 0000000 0000000 00000003775 14323200667 0024650 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::IpDiscover::Nmap;
use vars qw($runMeIfTheseChecksFailed);
$runMeIfTheseChecksFailed = ["Ocsinventory::Agent::Backend::IpDiscover::IpDiscover"];
use strict;
use warnings;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run("nmap");
return unless $common->can_load("Nmap::Parser");
# Do we have nmap 3.90 (or >)
foreach (`nmap -v 2>&1`) {
if (/^Starting Nmap (\d+)\.(\d+)/) {
my $release = $1;
my $minor = $2;
if ($release > 3 || ($release > 3 && $minor >= 90)) {
return 1;
}
}
}
0;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $prologresp = $params->{prologresp};
my $logger = $params->{logger};
# Let's find network interfaces and call ipdiscover on it
my $options = $prologresp->getOptionsInfoByName("IPDISCOVER");
my $network;
if ($options->[0] && exists($options->[0]->{content})) {
$network = $options->[0]->{content};
} else {
return;
}
unless ($network =~ /^\d+\.\d+\.\d+\.\d+$/) {
return;
}
#Let's go scanning the network and parsing the results
$logger->debug("Scanning the $network network");
my $nmaparser = new Nmap::Parser;
$nmaparser->parsescan("nmap","-sn","-PR","$network/24");
for my $host ($nmaparser->all_hosts("up")){
my $ip = $host->addr;
my $mac = $host->mac_addr;
my $hostname = $host->hostname;
if ($hostname eq 0) {
$hostname = undef; #it's better to send nothing instead of a '0'
}
if ($mac) {
$logger->debug("Host $ip found using Nmap. Adding informations in XML");
# Feeding the Inventory XML
$common->addIpDiscoverEntry({
IPADDRESS => $ip,
MACADDR => lc($mac),
NAME => $hostname,
});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/ 0000775 0000000 0000000 00000000000 14323200667 0021655 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX.pm 0000664 0000000 0000000 00000001507 14323200667 0022637 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX;
use strict;
use vars qw($runAfter);
$runAfter = ["Ocsinventory::Agent::Backend::OS::Generic"];
sub check {
my $r;
$r = 1 if $^O =~ /^aix$/;
$r;
}
sub run {
my $params = shift;
my $common = $params->{common};
my @tabOS;
my $OSName;
my $OSComment;
my $OSVersion;
my $OSLevel;
# Operating system informations
chomp($OSName=`uname -s`);
# AIX OSVersion = oslevel, OSComment=oslevel -r affiche niveau de maintenance
chomp($OSVersion=`oslevel`);
chomp($OSLevel=`oslevel -r`);
@tabOS=split(/-/,$OSLevel);
$OSComment="Maintenance Level :".@tabOS[1];
$OSVersion =~ s/(.0)*$//;
$common->setHardware({
OSNAME => "$OSName $OSVersion",
OSCOMMENTS => $OSComment,
OSVERSION => $OSLevel,
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/ 0000775 0000000 0000000 00000000000 14323200667 0022276 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/CPU.pm 0000664 0000000 0000000 00000004303 14323200667 0023263 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX::CPU;
use strict;
use warnings;
sub check { 1 }
# try to simulate a modern lsattr output on AIX4
sub lsattrForAIX4 {
my $device = shift;
my @lsattr;
my @lsattrtemp=`lsattr -EOl $device -a 'state:type'`;
for (@lsattrtemp) {
chomp;
my $frequency;
my (undef,$type)=split /:/;
#
# On older models, frequency is based on cpu model and uname
#
if ( $type eq "PowerPC" or $type eq "PowerPC_601" or $type eq "PowerPC_604") {
my $uname=`uname -m`;
$frequency=112000000 if ($uname=~/E1D|EAD|C1D|R04|C4D|R4D/);
$frequency=133000000 if ($uname=~/34M/);
$frequency=150000000 if ($uname=~/N4D/);
$frequency=200000000 if ($uname=~/X4M|X4D/);
$frequency=225000000 if ($uname=~/N4E|K04|K44/);
$frequency=320000000 if ($uname=~/N4F/);
$frequency=360000000 if ($uname=~/K45/);
} elsif ( $type eq "PowerPC_RS64_III" ) {
$frequency=400000000;
} elsif ( $type eq "PowerPC_620" ) {
$frequency=172000000;
} else {
$frequency=225000000;
}
push @lsattr,"$device:$frequency\n";
}
}
sub run {
my $params = shift;
my $common = $params->{common};
# TODO Need to be able to register different CPU speed!
my $processort;
my $processorn;
my $processors;
my $frequency;
my @lsdev;
my @lsattr;
#lsdev -Cc processor -F name
#lsattr -EOl proc16
my $aixversion=`uname -v`;
for (`lsdev -Cc processor -F name`){
chomp(my $device = $_);
if ( $aixversion < 5 ) {
@lsattr=lsattrForAIX4($device);
} else {
@lsattr=`lsattr -EOl $device -a 'state:type:frequency'`;
}
for (@lsattr) {
if ( ! /^#/ && /(.+):(.+):(.+)/ ) {
$processorn++;
$processort=$2;
if ( ($3 % 1000000) >= 50000){
$processors=int (($3/1000000) +1);
}
else {
$processors=int (($3/1000000));
}
}
}
}
$processort =~ s/_/ /;
$common->setHardware({
PROCESSORT => $processort,
PROCESSORN => $processorn,
PROCESSORS => $processors
});
}
1
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/Controller.pm 0000664 0000000 0000000 00000001414 14323200667 0024757 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX::Controller;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run('lsdev');
my @lsdev = `lsdev -Cc adapter -F 'name:type:description'`;
return 1 if @lsdev;
0
}
sub run {
my $params = shift;
my $common = $params->{common};
my $name;
my $type;
my $manufacturer;
for (`lsdev -Cc adapter -F 'name:type:description'`){
chomp($_);
/^(.+):(.+):(.+)/;
my $name = $1;
my $type = $2;
my $manufacturer = $3;
$common->addController({
'NAME' => $name,
'MANUFACTURER' => $manufacturer,
'TYPE' => $type,
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/Domains.pm 0000664 0000000 0000000 00000001223 14323200667 0024224 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX::Domains;
use strict;
sub run {
my $params = shift;
my $common = $params->{common};
my $domain;
# Domain name
open RESOLV, "/etc/resolv.conf";
while(){
if (/^(domain|search)\s+(.+)/){
$domain=$2;
chomp($domain);
}
}
# If no domain name and no workgroup name (samba), we send "WORKGROUP"
# TODO:Check if samba is present and get the windows workgroup or NT domain name
unless (defined($domain)){chomp($domain="WORKGROUP");}
$domain=~s/^.\.(.)/$1/;
$common->setHardware({
WORKGROUP => $domain
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/Drives.pm 0000664 0000000 0000000 00000002106 14323200667 0024067 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX::Drives;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run("df");
1;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $free;
my $filesystem;
my $total;
my $type;
my $volumn;
my @fs;
my @fstype;
#Looking for mount points and disk space
# Aix option -kP
for (`df -kP`) {
next if /^Filesystem\s*1024-blocks.*/;
if (/^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\n/) {
$volumn = $1;
@fs=`lsfs -c $6`;
@fstype = split /:/,$fs[1];
$filesystem = $fstype[2];
$total = sprintf("%i",($2/1024));
$free = sprintf("%i",($4/1024));
$type = $6;
}
next if $filesystem =~ /procfs/;
$common->addDrive({
FREE => $free,
FILESYSTEM => $filesystem,
TOTAL => $total,
TYPE => $type,
VOLUMN => $volumn
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/Hardware.pm 0000664 0000000 0000000 00000003723 14323200667 0024376 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX::Hardware;
use strict;
sub check { 1 }
# NOTE:
# Q: SSN can also use `uname -n`? What is the best?
# A: uname -n since it doesn't need root priv
sub run {
my $params = shift;
my $common = $params->{common};
# Using "type 0" section
my( $SystemSerial , $SystemModel, $SystemManufacturer, $BiosManufacturer, $BiosVersion, $BiosDate);
# lsvpd
my @lsvpd = `lsvpd`;
# Remove * (star) at the beginning of lines
s/^\*// for (@lsvpd);
# Search Firmware Hard
my $flag=0;
my $fw;
for (@lsvpd){
if (/^DS Platform Firmware/) { $flag=1 };
if ( ($flag) && /^RM (.+)/) {$fw=$1;chomp($fw);$fw =~ s/(\s+)$//g;last};
}
$flag=0;
for (@lsvpd){
if (/^DS System Firmware/) { $flag=1 };
if ( ($flag) && /^RM (.+)/) {$BiosVersion=$1;chomp($BiosVersion);$BiosVersion =~ s/(\s+)$//g;last};
}
$flag=0;
for (@lsvpd){
if (/^DS System VPD/) { $flag=1 };
if ( ($flag) && /^TM (.+)/) {$SystemModel=$1;chomp($SystemModel);$SystemModel =~ s/(\s+)$//g;};
if ( ($flag) && /^SE (.+)/) {$SystemSerial=$1;chomp($SystemSerial);$SystemSerial =~ s/(\s+)$//g;};
if ( ($flag) && /^FC .+/) {$flag=0;last}
}
# Fetch the serial number like prtconf do
if (! $SystemSerial) {
$flag=0;
foreach (`lscfg -vpl sysplanar0`) {
if ($flag) {
if (/\.+(\S*?)$/) {
$SystemSerial = $1;
}
last;
} else {
$flag = 1 if /\s+System\ VPD/;
}
}
}
$BiosManufacturer='IBM';
$SystemManufacturer='IBM';
$BiosVersion .= "(Firmware :".$fw.")";
# Writing data
$common->setBios ({
SMANUFACTURER => $SystemManufacturer,
SMODEL => $SystemModel,
SSN => $SystemSerial,
BMANUFACTURER => $BiosManufacturer,
BVERSION => $BiosVersion,
BDATE => $BiosDate,
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/IPv4.pm 0000664 0000000 0000000 00000001103 14323200667 0023411 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX::IPv4;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("ifconfig")
}
# Initialise the distro entry
sub run {
my $params = shift;
my $common = $params->{common};
my @ip;
# Looking for ip addresses with ifconfig, except loopback
# AIX need -a option
for (`ifconfig -a`){#ifconfig in the path
# AIX ligne inet
if(/^\s*inet\s+(\S+).*/){($1=~/^127.+/)?next:push @ip, $1};
}
$ip=join "/", @ip;
$common->setHardware({IPADDR => $ip});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/LVM.pm 0000664 0000000 0000000 00000007306 14323200667 0023300 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX::LVM;
use strict;
use vars qw($runAfter);
$runAfter = ["Ocsinventory::Agent::Backend::OS::AIX::Drives"];
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run ("lspv") || $common->can_run('lsvg') || $common->can_run('lslv');
1
}
my $line;
sub run {
my $params = shift;
my $common = $params->{common};
my @physvol;
my @volgrp;
my $format;
my $total;
my $total_pps;
my $free;
my $free_pps;
my $lps;
my $volume_name;
my $volume_size;
my $volume_uuid;
my $status;
my $vg_name;
my $type;
use constant MB => (1024*1024);
# We retrieve the disk list
foreach my $line (`lspv`) {
chomp;
my ($name) = split(/\s+/, $line);
push @physvol, $name;
}
foreach my $nom (@physvol) {
foreach my $line (`lspv $nom`){
if ($line =~ /PHYSICAL VOLUME:\s+(\S+)/) {
$format = "AIX PV";
}
if ($line =~ /PV STATE:\ss+(\S+)/) {
$status = $1;
}
if ($line =~ /FREE PPs:\s+(\d+)/) {
$free_pps = $1;
}
if ($line =~ /TOTAL PPs:\s+(\d+)/) {
$total_pps = $1;
}
if ($line =~ /VOLUME GROUP:\s+(\S+)/) {
$vg_name = "VG $1";
}
if ($line =~ /PP SIZE:\s+(\d+)/) {
$volume_size = $1;
}
if ($line =~ /PV IDENTIFIER:\s+(\S+)/) {
$volume_uuid = $1;
}
if ($volume_size){
$total = $total_pps * $volume_size;
$free = $free_pps * $volume_size;
}
$common->addDrive({
FREE => $free,
FILESYSTEM => $format,
TOTAL => $total,
TYPE => "DISK",
VOLUMN => $status,
SERIAL => $volume_uuid
});
}
}
foreach my $nom (@physvol) {
foreach my $line (`lslv $nom`){
if ($line =~ /LV IDENTIFIER:\s+(\S+)/) {
$volume_uuid = $1;
}
if ($line =~ /LV STATE:\s+(\S+)/) {
$status = $1;
}
if ($line =~ /PP SIZE:\s+(\d+)/) {
$volume_size = $1;
}
if ($line =~ /LPs:\s+(\d+)/) {
$lps = $1;
}
if ($line =~ /TYPE:\s+(\S+)/) {
$type = $1;
}
$total = $lps * $volume_size;
$common->addDrive({
FREE => "",
FILESYSTEM => "",
TOTAL => $total,
TYPE => $type,
VOLUMN => $status,
SERIAL => $volume_uuid
});
}
}
# We retrieve the disk list
foreach my $line (`lsvg`) {
chomp;
my ($name) = split(/\s+/, $line);
push @volgrp, $name;
}
foreach my $nom (@volgrp) {
foreach my $line (`lsvg $nom`){
if ($line =~ /VG IDENTIFIER:\s+(\S+)/) {
$volume_uuid = $1;
}
if ($line =~ /VG STATE:\s+(\S+)/) {
$status = $1;
}
if ($line =~ /TOTAL PPs:\s+(\d+)/) {
$volume_size = $1;
}
if ($line =~ /FREE PPs:\s+(\d+)/) {
$free = $1;
}
$common->addDrive({
FREE => $free,
FILESYSTEM => "",
TOTAL => $volume_size,
TYPE => "AIX VG",
VOLUMN => $status,
SERIAL => $volume_uuid
});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/Mem.pm 0000664 0000000 0000000 00000001607 14323200667 0023356 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX::Mem;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run("lsdev");
return unless $common->can_run("which");
return unless $common->can_run("lsattr");
}
sub run {
my $params = shift;
my $common = $params->{common};
my $memory;
my $swap;
# Memory informations
# lsdev -Cc memory -F 'name' -t totmem
# lsattr -EOlmem0
my (@lsdev, @lsattr, @grep);
$memory=0;
@lsdev=`lsdev -Cc memory -F 'name' -t totmem`;
for (@lsdev){
$memory += `lsattr -a size -F value -El$_`;
}
# Paging Space
@grep=`lsps -s`;
for (@grep){
if ( ! /^Total/){
/^\s*(\d+)\w*\s+\d+.+/;
$swap=$1;
}
}
$common->setHardware({
MEMORY => $memory,
SWAP => $swap
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/Memory.pm 0000664 0000000 0000000 00000003556 14323200667 0024115 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX::Memory;
use strict;
sub check { 1 } # TODO create a better check here
sub run {
my $params = shift;
my $common = $params->{common};
my $capacity;
my $description;
my $numslots;
my $speed;
my $type;
my $n;
my $serial;
my $mversion;
my $caption;
my $flag=0;
#lsvpd
my @lsvpd = `lsvpd`;
# Remove * (star) at the beginning of lines
s/^\*// for (@lsvpd);
$numslots = -1;
for (@lsvpd){
if (/^DS Memory DIMM/){
$description = $_;
$flag=1; (defined($n))?($n++):($n=0);
$description =~ s/DS //;
$description =~ s/\n//;
}
if((/^SZ (.+)/) && ($flag)) {$capacity = $1;}
if((/^PN (.+)/) && ($flag)) {$type = $1;}
# localisation slot dans type
if((/^YL\s(.+)/) && ($flag)) {$caption = "Slot ".$1;}
if((/^SN (.+)/) && ($flag)) {$serial = $1;}
if((/^VK (.+)/) && ($flag)) {$mversion = $1};
#print $numslots."\n";
# On rencontre un champ FC alors c'est la fin pour ce device
if ((/^FC .+/) && ($flag)) {
$flag=0;
$numslots = $numslots +1;
$common->addMemory({
CAPACITY => $capacity,
DESCRIPTION => $description,
CAPTION => $caption,
NUMSLOTS => $numslots,
VERSION => $mversion,
TYPE => $type,
SERIALNUMBER=> $serial,
});
}
}
#$numslots = $numslots +1;
# End of Loop
# The last *FC ???????? missing
# $common->addMemory({
# CAPACITY => $capacity,
# DESCRIPTION => $description,
# CAPTION => $caption,
# NUMSLOTS => $numslots,
# VERSION => $mversion,
# TYPE => $type,
# SERIALNUMBER=> $serial,
#});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/Modems.pm 0000664 0000000 0000000 00000001067 14323200667 0024064 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX::Modems;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("lsdev")
}
sub run {
my $params = shift;
my $common = $params->{common};
for (`lsdev -Cc adapter -F 'name:type:description'`){
if (/modem/i && /\d+\s(.+):(.+)$/){
my $name = $1;
my $description = $2;
$common->addModems({
'DESCRIPTION' => $description,
'NAME' => $name,
});
}
}
}
1
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/Networks.pm 0000664 0000000 0000000 00000010021 14323200667 0024442 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX::Networks;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_load("Net::IP qw(:PROC)");
}
sub run {
my $params = shift;
my $common = $params->{common};
my %info;
my $ifname;
foreach (`lscfg -v -l en*`) {
$ifname = "en".$1 if /^\s+ent(\d+)\s+\S+\s+(.+)/;
if ($ifname) {
$info{$ifname}{type} = $2;
$info{$ifname}{status} = "Down"; # default is down
if (/Network Address\.+(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})/) {
$info{$ifname}{macaddr} = "$1:$2:$3:$4:$5:$6"
}
}
}
# Retrieve VLAN information on AIX
# Only tested on AIX 6.1
my $pifname;
foreach (`lsdev`) {
if (/^ent(\d+).*VLAN$/) {
$ifname = "en".$1;
$pifname = "ent".$1;
$info{$ifname}{type} = "VLAN";
$info{$ifname}{status} = "Down";
foreach (`entstat -d $ifname`) {
if (/Hardware Address:\s+(.+)$/) {
$info{$ifname}{macaddr}="$1";
last;
}
}
foreach (`lsattr -El $pifname`) {
if (/^vlan_tag_id\s+(\d+)/) {
$info{$ifname}{type}.="$1";
}
}
}
}
# uncomment if you prefere verbose information about the link
# e.g: 0xe8120000:0xe80c0000:741:3:512:1024:8192:Auto_Negotiation:2048:no:0x000000000000:10000:10:1000:yes:yes:no:no:yes:2048
# etherchannel interfaces
# my @lsdev=`lsdev -Cc adapter -s pseudo -t ibm_ech`;
# foreach (`lsdev -Cc adapter`) {
# next unless /^ent(\d*)\s*(\w*)\s*.*/;
# my $ifname = "en".$1;
# my $tmpifname = "ent".$1;
# #@lsattr=`lsattr -EOl $1 -a 'adapter_names mode netaddr'`;
# foreach (`lsattr -EOl $tmpifname`) {
# if (/(.+):(.+):(.*)/) {
# $info{$ifname}{type}="EtherChannel with : ".$1." (mode :".$2.", ping :".$3.")";
# }
# }
# $info{$ifname}{status} = 'Down'; # The same
# }
foreach (split / /,`ifconfig -l`) {
# AIX: network interface naming is enX
if (/^(en\d+)/) {
my $ifname = $1;
foreach (`lsattr -E -l $ifname`) {
$info{$ifname}{ip} = $1 if /^netaddr \s*([\d*\.?]*).*/i;
$info{$ifname}{netmask} = $1 if /^netmask\s*([\d*\.?]*).*/i;
$info{$ifname}{status} = $1 if /^state\s*(\w*).*/i;
}
}
}
# Looking for the gateways
# AIX: the route command doesn't exist. We use netstat -rn instead
foreach (`netstat -rn`) {
if (/\S+\s+(\S+)\s+\S+\s+\S+\s+\S+\s+(\S+)/) {
my $ifname = $2;
my $gateway = $1;
if (exists ($info{$ifname})) {
$info{$ifname}{gateway} = $gateway;
}
}
}
foreach my $ifname (sort keys %info) {
my $description = $ifname;
my $type = $info{$ifname}{type};
my $macaddr = $info{$ifname}{macaddr};
my $status = $info{$ifname}{status};
my $ipaddress = $info{$ifname}{ip};
my $ipmask = $info{$ifname}{netmask};
my $gateway = $info{$ifname}{gateway};
my $ipdhcp = "No";
my $ipsubnet;
$status = "Down" unless $ipaddress;
# Retrieving ip of the subnet for each interface
if ($ipmask and $ipaddress) {
# To retrieve the subnet for this iface
my $binip = &ip_iptobin ($ipaddress ,4);
my $binmask = &ip_iptobin ($ipmask ,4);
my $subnet = $binip & $binmask;
$ipsubnet = ip_bintoip($subnet,4);
}
$common->addNetwork({
DESCRIPTION => $description,
IPADDRESS => $ipaddress,
IPDHCP => $ipdhcp,
IPGATEWAY => $gateway,
IPMASK => $ipmask,
IPSUBNET => $ipsubnet,
MACADDR => $macaddr,
STATUS => $status,
TYPE => $type,
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/Slots.pm 0000664 0000000 0000000 00000002027 14323200667 0023741 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX::Slots;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("lsdev")
}
sub run {
my $params = shift;
my $common = $params->{common};
my $description;
my $designation;
my $name;
my $status;
my @slot;
my $flag=0;
@slot=`lsdev -Cc bus -F 'name:description'`;
for (@slot){
/^(.+):(.+)/;
$name = $1;
$status = 'available';
$designation = $2;
$flag=0;
my @lsvpd = `lsvpd`;
s/^\*// for (@lsvpd);
for (@lsvpd){
if ((/^AX $name/) ) {$flag=1}
if ((/^YL (.+)/) && ($flag)){
$description = $2;
}
if ((/^FC .+/) && $flag) {$flag=0;last}
}
$common->addSlot({
DESCRIPTION => $description,
DESIGNATION => $designation,
NAME => $name,
STATUS => $status,
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/Software.pm 0000664 0000000 0000000 00000001452 14323200667 0024430 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX::Software;
use strict;
use warnings;
sub check {
my $params = shift;
my $common = $params->{common};
# Do not run an package inventory if there is the --nosoftware parameter
return if ($params->{config}->{nosoftware});
return unless $common->can_run("lslpp");
1;
}
sub run {
my $params = shift;
my $common = $params->{common};
my @list;
my $buff;
foreach (`lslpp -c -l`) {
my @entry = split /:/,$_;
next unless (@entry);
next unless ($entry[1]);
next if $entry[1] =~ /^device/;
$common->addSoftware({
'COMMENTS' => $entry[6],
'FOLDER' => $entry[0],
'NAME' => $entry[1],
'VERSION' => $entry[2],
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/Sounds.pm 0000664 0000000 0000000 00000001121 14323200667 0024102 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX::Sounds;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("lsdev")
}
sub run {
my $params = shift;
my $common = $params->{common};
for (`lsdev -Cc adapter -F 'name:type:description'`){
if (/audio/i){
if (/^\S+\s([^:]+):\s*(.+?)(?:\(([^()]+)\))?$/i){
$common->addSound({
'DESCRIPTION' => $3,
'MANUFACTURER' => $2,
'NAME' => $1,
});
}
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/Storages.pm 0000664 0000000 0000000 00000017776 14323200667 0024445 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX::Storages;
use strict;
#use warning;
sub check {
`which lsdev 2>&1`;
return if($? >> 8)!=0;
`which lsattr 2>&1`;
($? >> 8)?0:1}
sub run {
my $params = shift;
my $common = $params->{common};
my(@disques, $device, $model, $capacity, $description, $manufacturer, $n, $i, $flag, @rep, @scsi, @values, @lsattr, $FRU, $status);
#lsvpd
my @lsvpd = `lsvpd`;
s/^\*// for (@lsvpd);
#FCP MPIO FC 2145 disks. IBM SDDPCM MPIO Storwize
@scsi= ();
@lsattr= ();
$n=0;
@scsi=`lsdev -Cc disk -s fcp -F 'name:description'`;
for (@scsi){
chomp $scsi[$n];
/^(.+):(.+)/;
$device=$1;
$description=$2;
@lsattr=`lspv $device 2>&1`;
for (@lsattr){
if ( ! ( /^0516-320.*/ ) ){
if (/TOTAL PPs:/ ) {
($capacity,$model) = split(/\(/, $_);
($capacity,$model) = split(/ /,$model);
}
} else{
$capacity=0;
}
}
$common->addStorages({
MANUFACTURER => "FCP",
MODEL => "MPIO Disk",
DESCRIPTION => $description,
TYPE => 'disk',
NAME => $device,
DISKSIZE => $capacity
});
$n++;
}
# SAS disks
$n=0;
@scsi=`lsdev -Cc disk -s sas -F 'name:description'`;
for (@scsi){
chomp $scsi[$n];
/^(.+):(.+)/;
$device=$1;
$description=$2;
@lsattr=`lsattr -EOl $device -a 'size_in_mb'`;
for (@lsattr){
if (! /^#/ ){
$capacity=$_;
chomp($capacity);$capacity =~ s/(\s+)$//;
}
}
for (@lsvpd){
if (/^AX $device/){$flag=1}
if ((/^MF (.+)/) && $flag){$manufacturer=$1;chomp($manufacturer);$manufacturer =~ s/(\s+)$//;}
if ((/^TM (.+)/) && $flag){$model=$1;chomp($model);$model =~ s/(\s+)$//;}
if ((/^FN (.+)/) && $flag){$FRU=$1;chomp($FRU);$FRU =~ s/(\s+)$//;$manufacturer .= ",FRU number :".$FRU}
if ((/^FC .+/) && $flag) {$flag=0;last}
}
$common->addStorages({
MANUFACTURER => $manufacturer,
MODEL => $model,
DESCRIPTION => $description,
TYPE => 'disk',
NAME => $device,
DISKSIZE => $capacity
});
$n++;
}
#SCSI disks
$n=0;
@scsi=`lsdev -Cc disk -s scsi -F 'name:description'`;
for (@scsi){
chomp $scsi[$n];
/^(.+):(.+)/;
$device=$1;
$description=$2;
@lsattr=`lsattr -EOl $device -a 'size_in_mb'`;
for (@lsattr){
if (! /^#/ ){
$capacity= $_;
chomp($capacity);$capacity =~ s/(\s+)$//;
}
}
for (@lsvpd){
if(/^AX $device/){$flag=1}
if ((/^MF (.+)/) && $flag){$manufacturer=$1;chomp($manufacturer);$manufacturer =~ s/(\s+)$//;}
if ((/^TM (.+)/) && $flag){$model=$1;chomp($model);$model =~ s/(\s+)$//;}
if ((/^FN (.+)/) && $flag){$FRU=$1;chomp($FRU);$FRU =~ s/(\s+)$//;$manufacturer .= ",FRU number :".$FRU}
if ((/^FC .+/) && $flag) {$flag=0;last}
}
$common->addStorages({
NAME => $device,
MANUFACTURER => $manufacturer,
MODEL => $model,
DESCRIPTION => $description,
TYPE => 'disk',
DISKSIZE => $capacity
});
$n++;
}
#Virtual disks
@scsi= ();
@lsattr= ();
$n=0;
@scsi=`lsdev -Cc disk -s vscsi -F 'name:description'`;
for (@scsi){
chomp $scsi[$n];
/^(.+):(.+)/;
$device=$1;
$description=$2;
@lsattr=`lspv $device 2>&1`;
for (@lsattr){
if ( ! ( /^0516-320.*/ ) ) {
if (/TOTAL PPs:/ ) {
($capacity,$model) = split(/\(/, $_);
($capacity,$model) = split(/ /,$model);
}
} else {
$capacity=0;
}
}
$common->addStorages({
MANUFACTURER => "VIO Disk",
MODEL => "Virtual Disk",
DESCRIPTION => $description,
TYPE => 'disk',
NAME => $device,
DISKSIZE => $capacity
});
$n++;
}
#CDROM
@scsi= ();
@lsattr= ();
@scsi=`lsdev -Cc cdrom -s scsi -F 'name:description:status'`;
$i=0;
for (@scsi){
chomp $scsi[$i];
/^(.+):(.+):(.+)/;
$device=$1;
$status=$3;
$description=$2;
$capacity="";
if (($status =~ /Available/)){
@lsattr=`lsattr -EOl $device -a 'size_in_mb'`;
for (@lsattr){
if (! /^#/ ){
$capacity= $_;
chomp($capacity);$capacity =~ s/(\s+)$//;
}
}
$description = $scsi[$n];
for (@lsvpd){
if(/^AX $device/){$flag=1}
if ((/^MF (.+)/) && $flag){$manufacturer=$1;chomp($manufacturer);$manufacturer =~ s/(\s+)$//;}
if ((/^TM (.+)/) && $flag){$model=$1;chomp($model);$model =~ s/(\s+)$//;}
if ((/^FN (.+)/) && $flag){$FRU=$1;chomp($FRU);$FRU =~ s/(\s+)$//;$manufacturer .= ",FRU number :".$FRU}
if ((/^FC .+/) && $flag) {$flag=0;last}
}
$common->addStorages({
NAME => $device,
MANUFACTURER => $manufacturer,
MODEL => $model,
DESCRIPTION => $description,
TYPE => 'cd',
DISKSIZE => $capacity
});
$n++;
}
$i++;
}
#TAPE
@scsi= ();
@lsattr= ();
@scsi=`lsdev -Cc tape -s scsi -F 'name:description:status'`;
$i=0;
for (@scsi){
chomp $scsi[$i];
/^(.+):(.+):(.+)/;
$device=$1;
$status=$3;
$description=$2;
$capacity="";
if (($status =~ /Available/)){
@lsattr=`lsattr -EOl $device -a 'size_in_mb'`;
for (@lsattr){
if (! /^#/ ){
$capacity= $_;
chomp($capacity);$capacity =~ s/(\s+)$//;
}
}
for (@lsvpd){
if(/^AX $device/){$flag=1}
if ((/^MF (.+)/) && $flag){$manufacturer=$1;chomp($manufacturer);$manufacturer =~ s/(\s+)$//;}
if ((/^TM (.+)/) && $flag){$model=$1;chomp($model);$model =~ s/(\s+)$//;}
if ((/^FN (.+)/) && $flag){$FRU=$1;chomp($FRU);$FRU =~ s/(\s+)$//;$manufacturer .= ",FRU number :".$FRU}
if ((/^FC .+/) && $flag) {$flag=0;last}
}
$common->addStorages({
NAME => $device,
MANUFACTURER => $manufacturer,
MODEL => $model,
DESCRIPTION => $description,
TYPE => 'tape',
DISKSIZE => $capacity
});
$n++;
}
$i++;
}
#Disquette
@scsi= ();
@lsattr= ();
@scsi=`lsdev -Cc diskette -F 'name:description:status'`;
$i=0;
for (@scsi){
chomp $scsi[$i];
/^(.+):(.+):(.+)/;
$device=$1;
$status=$3;
$description=$2;
$capacity="";
if (($status =~ /Available/)){
@lsattr=`lsattr -EOl $device -a 'fdtype'`;
for (@lsattr){
if (! /^#/ ){
$capacity= $_;
chomp($capacity);$capacity =~ s/(\s+)$//;
}
}
# On le force en retour taille disquette non affichable
$capacity ="";
$common->addStorages({
NAME => $device,
MANUFACTURER => 'N/A',
MODEL => 'N/A',
DESCRIPTION => $description,
TYPE => 'floppy',
DISKSIZE => ''
});
$n++;
}
$i++;
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/Users.pm 0000664 0000000 0000000 00000000762 14323200667 0023742 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX::Users;
sub check {
# Useless check for a posix system i guess
my @who = `who 2>/dev/null`;
return 1 if @who;
return;
}
# Initialise the distro entry
sub run {
my $params = shift;
my $common = $params->{common};
my %user;
# Logged on users
for (`who`){
$user{$1} = 1 if /^(\S+)./;
}
my $UsersLoggedIn = join "/", keys %user;
$common->setHardware ({ USERID => $UsersLoggedIn });
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/AIX/Videos.pm 0000664 0000000 0000000 00000001073 14323200667 0024066 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::AIX::Videos;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("lsdev");
}
sub run {
my $params = shift;
my $common = $params->{common};
for (`lsdev -Cc adapter -F 'name:type:description'`){
if (/graphics|vga|video/i){
if (/^\S+\s([^:]+):\s*(.+?)(?:\(([^()]+)\))?$/i){
$common->addVideo({
'CHIPSET' => $1,
'NAME' => $2,
});
}
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/BSD.pm 0000664 0000000 0000000 00000002120 14323200667 0022616 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::BSD;
use strict;
use vars qw($runAfter);
$runAfter = ["Ocsinventory::Agent::Backend::OS::Generic"];
sub check { $^O =~ /freebsd|openbsd|netbsd|gnukfreebsd|gnuknetbsd/ }
sub run {
my $params = shift;
my $common = $params->{common};
my $OSName;
my $OSComment;
my $OSVersion;
my $OSLevel;
my $OSArchi;
# Operating system informations
chomp($OSName=`uname -s`);
chomp($OSVersion=`uname -r`);
chomp($OSArchi=`uname -p`);
# Retrieve the origin of the kernel configuration file
my ($date, $origin, $kernconf);
for (`sysctl -n kern.version`) {
$date = $1 if /^\S.*\#\d+:\s*(.*)/;
($origin,$kernconf) = ($1,$2) if /^\s+(.+):(.+)$/;
}
$kernconf =~ s/\/.*\///; # remove the path
$OSComment = $kernconf." (".$date.")\n".$origin;
# if there is a problem use uname -v
chomp($OSComment=`uname -v`) unless $OSComment;
$common->setHardware({
OSNAME => $OSName." ".$OSArchi,
OSCOMMENTS => $OSComment,
OSVERSION => $OSVersion,
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/BSD/ 0000775 0000000 0000000 00000000000 14323200667 0022265 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/BSD/Archs/ 0000775 0000000 0000000 00000000000 14323200667 0023325 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/BSD/Archs/Alpha.pm 0000664 0000000 0000000 00000003154 14323200667 0024713 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::BSD::Archs::Alpha;
use strict;
sub check{
my $arch;
chomp($arch=`sysctl -n hw.machine`);
$arch eq "alpha";
}
sub run {
my $params = shift;
my $common = $params->{common};
my ($SystemSerial, $SystemModel, $SystemManufacturer, $BiosManufacturer, $BiosVersion, $BiosDate);
my ($processort, $processorn, $processors);
### Get system model with "sysctl hw.model"
#
# example on *BSD
# hw.model = AlphaStation 255 4/232
chomp($SystemModel=`sysctl -n hw.model`);
$SystemManufacturer = "DEC";
### Get processor type and speed in dmesg
#
# NetBSD: AlphaStation 255 4/232, 232MHz, s/n
# cpu0 at mainbus0: ID 0 (primary), 21064A-2
# OpenBSD: AlphaStation 255 4/232, 232MHz
# cpu0 at mainbus0: ID 0 (primary), 21064A-2 (pass 1.1)
# FreeBSD: AlphaStation 255 4/232, 232MHz
# CPU: EV45 (21064A) major=6 minor=2
for (`dmesg`) {
if (/^cpu[^:]*:\s*(.*)$/i) { $processort = $1; }
if (/$SystemModel,\s*(\S+)\s*MHz.*$/) { $processors = $1; }
}
# number of procs with sysctl (hw.ncpu)
chomp($processorn=`sysctl -n hw.ncpu`);
# Writing data
$common->setBios ({
SMANUFACTURER => $SystemManufacturer,
SMODEL => $SystemModel,
SSN => $SystemSerial,
BMANUFACTURER => $BiosManufacturer,
BVERSION => $BiosVersion,
BDATE => $BiosDate,
});
$common->setHardware({
PROCESSORT => $processort,
PROCESSORN => $processorn,
PROCESSORS => $processors
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/BSD/Archs/I386.pm 0000664 0000000 0000000 00000003042 14323200667 0024313 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::BSD::Archs::I386;
# for i386 in case dmidecode is not available
use strict;
sub check{
my $arch;
chomp($arch=`sysctl -n hw.machine`);
return if (($arch ne "i386") && ($arch ne "amd64"));
# dmidecode must not be present
`dmidecode 2>&1`;
return if ($? >> 8)==0;
1;
}
sub run {
my $params = shift;
my $common = $params->{common};
my ($SystemSerial , $SystemModel, $SystemManufacturer, $BiosManufacturer, $BiosVersion, $BiosDate);
my ($processort , $processorn , $processors);
# use hw.machine for the system model
# TODO see if we can do better
chomp($SystemModel=`sysctl -n hw.machine`);
# number of procs with sysctl (hw.ncpu)
chomp($processorn=`sysctl -n hw.ncpu`);
# proc type with sysctl (hw.model)
chomp($processort=`sysctl -n hw.model`);
# XXX quick and dirty _attempt_ to get proc speed through dmesg
for (`dmesg`){
my $tmp;
if (/^cpu\S*\s.*\D[\s|\(]([\d|\.]+)[\s|-]mhz/i) { # XXX unsure
$tmp = $1;
$tmp =~ s/\..*//;
$processors=$tmp;
last
}
}
# Writing data
$common->setBios ({
SMANUFACTURER => $SystemManufacturer,
SMODEL => $SystemModel,
SSN => $SystemSerial,
BMANUFACTURER => $BiosManufacturer,
BVERSION => $BiosVersion,
BDATE => $BiosDate,
});
$common->setHardware({
PROCESSORT => $processort,
PROCESSORN => $processorn,
PROCESSORS => $processors
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/BSD/Archs/Sgimips.pm 0000664 0000000 0000000 00000004010 14323200667 0025271 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::BSD::Archs::Sgimips;
use strict;
sub check{
my $arch;
chomp($arch=`sysctl -n hw.machine`);
$arch =~ m/^sgi/;
}
sub run {
my $params = shift;
my $common = $params->{common};
my ($SystemSerial , $SystemModel, $SystemManufacturer, $BiosManufacturer, $BiosVersion, $BiosDate);
my ($processort , $processorn , $processors );
### Get system model with "sysctl hw.model"
#
# example on NetBSD
# hw.model = SGI-IP22
# example on OpenBSD
# hw.model=SGI-O2 (IP32)
chomp($SystemModel=`sysctl -n hw.model`);
$SystemManufacturer = "SGI";
### Get processor type and speed in dmesg
#
# Examples of dmesg output :
#
# I) Indy
# a) NetBSD
# mainbus0 (root): SGI-IP22 [SGI, 6906e152], 1 processor
# cpu0 at mainbus0: MIPS R4400 CPU (0x450) Rev. 5.0 with MIPS R4010 FPC Rev. 0.0
# int0 at mainbus0 addr 0x1fbd9880: bus 75MHz, CPU 150MHz
#
# II) O2
# a) NetBSD
# mainbus0 (root): SGI-IP32 [SGI, 8], 1 processor
# cpu0 at mainbus0: MIPS R5000 CPU (0x2321) Rev. 2.1 with built-in FPU Rev. 1.0
# b) OpenBSD
# mainbus0 (root)
# cpu0 at mainbus0: MIPS R5000 CPU rev 2.1 180 MHz with R5000 based FPC rev 1.0
# cpu0: cache L1-I 32KB D 32KB 2 way, L2 512KB direct
for (`dmesg`) {
if (/$SystemModel\s*\[\S*\s*(\S*)\]/) { $SystemSerial = $1; }
if (/cpu0 at mainbus0:\s*(.*)$/) { $processort = $1; }
if (/CPU\s*.*\D(\d+)\s*MHz/) { $processors = $1; }
}
# number of procs with sysctl (hw.ncpu)
chomp($processorn=`sysctl -n hw.ncpu`);
# Writing data
$common->setBios ({
SMANUFACTURER => $SystemManufacturer,
SMODEL => $SystemModel,
SSN => $SystemSerial,
BMANUFACTURER => $BiosManufacturer,
BVERSION => $BiosVersion,
BDATE => $BiosDate,
});
$common->setHardware({
PROCESSORT => $processort,
PROCESSORN => $processorn,
PROCESSORS => $processors
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/BSD/Archs/Sparc.pm 0000664 0000000 0000000 00000005631 14323200667 0024740 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::BSD::Archs::Sparc;
use strict;
sub check{
my $arch;
chomp($arch=`sysctl -n hw.machine`);
$arch =~ /^sparc/;
}
sub run {
my $params = shift;
my $common = $params->{common};
my( $SystemSerial , $SystemModel, $SystemManufacturer, $BiosManufacturer,
$BiosVersion, $BiosDate);
my ( $processort , $processorn , $processors );
### Get system serial with "sysctl kern.hostid"
#
# sysctl -n kern.hostid gives e.g. 0x807b65c on NetBSD
# and 2155570635 on OpenBSD; we keep the hex form
chomp ($SystemSerial = `sysctl -n kern.hostid`);
if ( $SystemSerial =~ /^\d*$/ ) { # convert to NetBSD format
$SystemSerial = sprintf ("0x%x",$SystemSerial);
}
$SystemSerial =~ s/^0x//; # remove 0x to make it appear as in the firmware
### Get system model and processor type in dmesg
#
# cannot use "sysctl hw.model" to get SystemModel
# because it gives only the CPU on OpenBSD/sparc64
#
# Examples of dmesg output :
#
# I) SPARC
# a) NetBSD
# mainbus0 (root): SUNW,SPARCstation-20: hostid 72362bb1
# cpu0 at mainbus0: TMS390Z50 v0 or TMS390Z55 @ 50 MHz, on-chip FPU
# b) OpenBSD
# mainbus0 (root): SUNW,SPARCstation-20
# cpu0 at mainbus0: TMS390Z50 v0 or TMS390Z55 @ 50 MHz, on-chip FPU
#
# II) SPARC64
# a) NetBSD
# mainbus0 (root): SUNW,Ultra-1: hostid 807b65cb
# cpu0 at mainbus0: SUNW,UltraSPARC @ 166.999 MHz, version 0 FPU
# b) OpenBSD
# mainbus0 (root): Sun Ultra 1 SBus (UltraSPARC 167MHz)
# cpu0 at mainbus0: SUNW,UltraSPARC @ 166.999 MHz, version 0 FPU
# c) FreeBSD
# cpu0: Sun Microsystems UltraSparc-I Processor (167.00 MHz CPU)
for (`dmesg`) {
if (/^mainbus0 \(root\):\s*(.*)$/) { $SystemModel = $1; }
if (/^cpu[^:]*:\s*(.*)$/i) { $processort = $1 unless $processort; }
}
$SystemModel || chomp ($SystemModel = `sysctl -n hw.model`); # for FreeBSD
$SystemManufacturer = "SUN";
# some cleanup
$SystemModel =~ s/SUNW,//;
$SystemModel =~ s/[:\(].*$//;
$SystemModel =~ s/^\s*//;
$SystemModel =~ s/\s*$//;
$processort =~ s/SUNW,//;
$processort =~ s/^\s*//;
$processort =~ s/\s*$//;
# number of procs with "sysctl hw.ncpu"
chomp($processorn=`sysctl -n hw.ncpu`);
# XXX quick and dirty _attempt_ to get proc speed
if ( $processort =~ /(\d+)(\.\d+|)\s*mhz/i ) { # possible decimal point
$processors = sprintf("%.0f", "$1$2"); # round number
}
# Writing data
$common->setBios ({
SMANUFACTURER => $SystemManufacturer,
SMODEL => $SystemModel,
SSN => $SystemSerial,
BMANUFACTURER => $BiosManufacturer,
BVERSION => $BiosVersion,
BDATE => $BiosDate,
});
$common->setHardware({
PROCESSORT => $processort,
PROCESSORN => $processorn,
PROCESSORS => $processors
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/BSD/CPU.pm 0000664 0000000 0000000 00000002030 14323200667 0023245 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::BSD::CPU;
use strict;
sub check {
return unless -r "/dev/mem";
1;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $os;
my $processort;
my $processorn;
my $processors;
my $family;
my $manufacturer;
my $serial;
chomp($os = `uname -s`);
if ($os eq "FreeBSD") {
$processors = `sysctl -n hw.clockrate`;
} else {
$processors = `sysctl -n hw.cpuspeed`;
}
$processorn = `sysctl -n hw.ncpu`;
$processort = `sysctl -n hw.model`;
$family = `sysctl -n hw.machine`;
$serial = `sysctl -n hw.serialno`;
chomp($processort);
if ($processort =~ /Intel/) {
$manufacturer = "Intel";
}
if ($processort =~ /Advanced Micro|AMD/) {
$manufacturer = "AMD";
}
$common->addCPU({
CPUARCH => $family,
MANUFACTURER => $manufacturer,
CORES => $processorn,
TYPE => $processort,
SPEED => $processors,
SERIAL => $serial
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/BSD/Domains.pm 0000664 0000000 0000000 00000002106 14323200667 0024214 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::BSD::Domains;
use strict;
sub check {
my $hostname;
chomp ($hostname = `hostname`);
my @domain = split (/\./, $hostname);
shift (@domain);
return 1 if @domain;
-f "/etc/resolv.conf"
}
sub run {
my $params = shift;
my $common = $params->{common};
my $domain;
my %domain;
my @dns_list;
my $dns;
my $hostname;
chomp ($hostname = `hostname`);
my @domain = split (/\./, $hostname);
shift (@domain);
$domain = join ('.',@domain);
open RESOLV, "/etc/resolv.conf" or warn;
while(){
if (/^nameserver\s+(\S+)/i) {
push(@dns_list,$1);
} elsif (!$domain) {
$domain{$2} = 1 if (/^(domain|search)\s+(.+)/);
}
}
close RESOLV;
if (!$domain) {
$domain = join "/", keys %domain;
}
$dns=join("/",@dns_list);
# If no domain name, we send "WORKGROUP"
$domain = 'WORKGROUP' unless $domain;
$common->setHardware({
WORKGROUP => $domain,
DNS => $dns
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/BSD/Drives.pm 0000664 0000000 0000000 00000001617 14323200667 0024064 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::BSD::Drives;
use strict;
sub run {
my $params = shift;
my $common = $params->{common};
my $free;
my $filesystem;
my $total;
my $type;
my $volumn;
for my $t ("ffs","ufs","zfs") {
# OpenBSD has no -m option so use -k to obtain results in kilobytes
for (`df -P -t $t -k`){
if (/^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\n/){
$volumn = $1;
$filesystem = $t;
$total = sprintf("%i",$2/1024);
$free = sprintf("%i",$4/1024);
$type = $6;
$common->addDrive({
FREE => $free,
FILESYSTEM => $filesystem,
TOTAL => $total,
TYPE => $type,
VOLUMN => $volumn
});
}
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/BSD/IPv4.pm 0000664 0000000 0000000 00000001062 14323200667 0023404 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::BSD::IPv4;
sub check {
my @ifconfig = `ifconfig -a 2>/dev/null`;
return 1 if @ifconfig;
return;
}
# Initialise the distro entry
sub run {
my $params = shift;
my $common = $params->{common};
my @ip;
# Looking for ip addresses with ifconfig, except loopback
# *BSD need -a option
foreach (`ifconfig -a`){
if (/^\s*inet\s+(\S+)/){
($1=~/^127.+/)?next:push @ip, $1
};
}
my $ip=join "/", @ip;
$common->setHardware({IPADDR => $ip});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/BSD/Mem.pm 0000664 0000000 0000000 00000001332 14323200667 0023340 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::BSD::Mem;
use strict;
sub check {
`which sysctl 2>&1`;
return 0 if($? >> 8);
`which swapctl 2>&1`;
return 0 if($? >> 8);
1;
};
sub run {
my $params = shift;
my $common = $params->{common};
my $PhysicalMemory;
my $SwapFileSize;
# Swap
my @bsd_swapctl= `swapctl -sk`;
for (@bsd_swapctl){
$SwapFileSize=$1 if /total:\s*(\d+)/i;
}
# RAM
chomp($PhysicalMemory=`sysctl -n hw.physmem`);
$PhysicalMemory=$PhysicalMemory/1024;
# Send it to inventory object
$common->setHardware({
MEMORY => sprintf("%i",$PhysicalMemory/1024),
SWAP => sprintf("%i", $SwapFileSize/1024),
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/BSD/Networks.pm 0000664 0000000 0000000 00000015525 14323200667 0024447 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::BSD::Networks;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("ifconfig") && $common->can_load("Net::IP qw(:PROC)")
}
sub _ipdhcp {
my $if = shift;
my $path;
my $ipdhcp;
my $leasepath;
foreach ( # XXX BSD paths
"/var/db/dhclient.leases.%s",
"/var/db/dhclient.leases",
# Linux path for some kFreeBSD based GNU system
"/var/lib/dhcp3/dhclient.%s.leases",
"/var/lib/dhcp3/dhclient.%s.leases",
"/var/lib/dhcp/dhclient.leases") {
$leasepath = sprintf($_,$if);
last if (-e $leasepath);
}
return undef unless -e $leasepath;
if (open DHCP, $leasepath) {
my $lease;
my $dhcp;
my $expire;
# find the last lease for the interface with its expire date
while(){
$lease = 1 if(/lease\s*{/i);
$lease = 0 if(/^\s*}\s*$/);
if ($lease) { #inside a lease section
if (/interface\s+"(.+?)"\s*/){
$dhcp = ($1 =~ /^$if$/);
}
#Server IP
if (/option\s+dhcp-server-identifier\s+(\d{1,3}(?:\.\d{1,3}){3})\s*;/x) {
$ipdhcp = $1;
}
if (/^\s*expire\s*\d\s*(\d*)\/(\d*)\/(\d*)\s*(\d*):(\d*):(\d*)/x) {
$expire=sprintf "%04d%02d%02d%02d%02d%02d",$1,$2,$3,$4,$5,$6;
}
}
}
close DHCP or warn;
chomp (my $currenttime = `date +"%Y%m%d%H%M%S"`);
undef $ipdhcp unless $currenttime <= $expire;
} else {
warn "Can't open $leasepath\n";
}
return $ipdhcp;
}
# Initialise the distro entry
sub run {
my $params = shift;
my $common = $params->{common};
my $description;
my $duplex;
my $ipaddress;
my $ipmask;
my $ipsubnet;
my $ipaddress6;
my $ipmask6;
my $ipsubnet6;
my $macaddr;
my $mtu;
my $speed;
my $status;
my $type;
my @ifconfig = `ifconfig -a`; # -a option required on *BSD
# first make the list available interfaces
# too bad there's no -l option on OpenBSD
my @list;
foreach (@ifconfig){
# skip loopback, pseudo-devices and point-to-point interfaces
next if /^(lo|fwe|vmnet|sit|pflog|pfsync|enc|strip|plip|sl|ppp)\d+/;
if (/^(\S+):/) { push @list , $1; } # new interface name
}
# for each interface get it's parameters
foreach $description (@list) {
$ipaddress = $ipmask = $macaddr = $status = $type = $mtu = $speed = $ipaddress6 = $ipmask6 = $ipsubnet6 = undef;
# search interface infos
@ifconfig = `ifconfig $description`;
foreach (@ifconfig){
$ipaddress = $1 if /inet (\S+)/i;
if (/inet6 ([\w:]+)\S* prefixlen (\d+)/) {
$ipaddress6=$1;
$ipmask6=getIPNetmaskV6($2);
$ipsubnet6=getSubnetAddressIPv6($ipaddress6,$ipmask6);
}
$ipmask = $1 if /netmask\s+(\S+)/i;
$macaddr = $2 if /(address:|ether|lladdr)\s+(\S+)/i;
$status = 1 if /)
$mtu = $1 if /mtu (\d+)/i;
}
# In BSD, netmask is given in hex form
my $binmask = sprintf("%b", oct($ipmask));
$ipmask = ip_bintoip($binmask,4);
if ($description & $ipaddress ) {
$common->addNetwork({
DESCRIPTION => $description,
IPADDRESS => $ipaddress,
IPDHCP => _ipdhcp($description),
IPGATEWAY => getRoute($ipaddress),
IPMASK => $ipmask,
IPSUBNET => getSubnetAddressIPv4($ipaddress,$ipmask),
MACADDR => $macaddr,
MTU => $mtu,
SPEED => getSpeed($speed),
STATUS => $status?"Up":"Down",
TYPE => $type,
});
# Set default gateway in hardware info
$common->setHardware({
DEFAULTGATEWAY => getRoute($ipaddress6)
});
} else {
$common->addNetwork({
DESCRIPTION => $description,
IPADDRESS => $ipaddress6,
IPDHCP => _ipdhcp($description),
IPGATEWAY => getRoute($ipaddress6),
IPMASK => getIPNetmaskV6($ipaddress6),
IPSUBNET => getSubnetAddressIPv6($ipaddress6,$ipmask6),
MACADDR => $macaddr,
MTU => $mtu,
SPEED => getSpeed($speed),
STATUS => $status?"Up":"Down",
TYPE => $type,
});
# Set default gateway in hardware info
$common->setHardware({
DEFAULTGATEWAY => getRoute($ipaddress6)
});
}
}
}
sub getSpeed{
my ($speed)=@_;
return unless $speed;
if ($speed gt 100 ){
$speed = ($speed/1000)." Gbps";
} else {
$speed = $speed." Mbps";
}
return $speed;
}
sub getSubnetAddressIPv4 {
my ($address,$mask)=@_;
return undef unless $address && $mask;
my $binaddress=ip_iptobin($address, 4);
my $binmask=ip_iptobin($mask, 4);
my $binsubnet=$binaddress & $binmask;
return ip_bintoip($binsubnet, 4);
}
sub getSubnetAddressIPv6 {
my ($address,$mask)=@_;
return undef unless $address && $mask;
my $binaddress = ip_iptobin(ip_expand_address($address, 6),6);
my $binmask = ip_iptobin(ip_expand_address($mask, 6),6);
my $binsubnet = $binaddress & $binmask;
return ip_compress_address(ip_bintoip($binsubnet, 6),6);
}
sub getIPNetmaskV6 {
my ($prefix) = @_;
return undef unless $prefix;
return ip_compress_address(ip_bintoip(ip_get_mask($prefix, 6), 6),6);
}
sub getRoute {
# Looking for the gateway
# 'route show' doesn't work on FreeBSD so we use netstat
# XXX IPV4 only
my ($prefix) = @_;
my $route;
return undef unless $prefix;
if (ip_is_ipv4($prefix)) {
for (`netstat -rn -f inet`){
$route = $1 if /^default\s+(\S+)/i;
}
} elsif (ip_is_ipv6($prefix)) {
for (`netstat -rn -f inet6`){
$route = $1 if /^default\s+(\S+)/i;
}
}
return $route;
}
1;
__END__
=head1 NAME
OCSInventory::Agent::Backend::OS::BSD::Networks - Network-related information
=head1 DESCRIPTION
This module retrieves network information.
=head1 FUNCTIONS
=head2 getSpeed
Returns the speed of the card.
=head2 getRoute
Returns the gateway
=head2 getIPNetmaskV4
Returns the IP v4 network mask
=head2 getIPNetmaskV6
Returns the IP v6 network mask
=head2 getSubnetAddressIPv4
Returns the subnet of ip v4 network
=head2 getSubnetAddressIPv6
Returns the subnet of ip v6 network
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/BSD/Storages.pm 0000664 0000000 0000000 00000004040 14323200667 0024410 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::BSD::Storages;
use strict;
sub check { -x '/usr/local/bin/smartctl'; }
sub run {
my $params = shift;
my $common = $params->{common};
my @values;
my $devlist;
my $osname = `uname -s`;
if (chomp($osname) eq "FreeBSD") {
$devlist = `/sbin/sysctl -n kern.disks`;
} else {
$devlist = `/sbin/sysctl -n hw.disknames`;
}
chomp($devlist);
my @devices = split( /\s+/, $devlist );
for my $dev (@devices) {
open( CMD, "smartctl -i /dev/$dev |" );
my ( $manufacturer, $serialnumber, $model, $size, $firmware, $type, $desc, $luwwnid );
while () {
chomp();
if (/^Vendor:\s+|^Model Family:\s+/i) {
$manufacturer = ( split( /:\s+/, $_ ) )[1];
}
if (/^Product:\s+|^Device Model:\s+/i) {
$model = ( split( /:\s+/, $_ ) )[1];
}
if (/^Serial number:\s+/i) {
$serialnumber = ( split( /:\s+/, $_ ) )[1];
}
if (/^User Capacity:\s+/i) {
s/,//g;
my $out = ( split( /:\s+/, $_ ) )[1];
$size = ( split( ' ', $out ) )[0] / ( 1024 * 1024 );
}
if (/^Revision:\s+|^Firmware Version:\s+/) {
$firmware = ( split( /:\s+/, $_ ) )[1];
}
if (/^Device type:\s+/) { $type = ( split( /:\s+/, $_ ) )[1]; }
if (/^Transport protocol:\s+/) {
$desc = ( split( /:\s+/, $_ ) )[1];
}
if (/^LU WWN Device Id:\s+/) {
$luwwnid = ( split( /:\s+/, $_ ) )[1];
}
}
$common->addStorages({
NAME => $dev,
MANUFACTURER => $manufacturer,
MODEL => $model,
DESCRIPTION => $desc,
TYPE => $type,
DISKSIZE => $size,
SERIALNUMBER => $serialnumber,
FIRMWARE => $firmware,
SCSI_UNID => $luwwnid,
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/BSD/Sys.pm 0000664 0000000 0000000 00000000405 14323200667 0023400 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::BSD::Sys;
#$LunchAfter = "Ocsinventory::Agent::Backend::OS::Linux::VirtualFs::Sys";
sub check {
foreach (`mount`) {
return 1 if (/type\ sysfs/);
}
return;
}
sub run {
# Hum?
return "";
}
1
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/BSD/Uptime.pm 0000664 0000000 0000000 00000001605 14323200667 0024070 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::BSD::Uptime;
use strict;
sub check {
my $boottime = `sysctl -n kern.boottime 2>/dev/null`;
return 1 if $boottime;
return;
}
sub run {
my $params = shift;
my $common = $params->{common};
chomp (my $boottime = `sysctl -n kern.boottime`);
$boottime = $1 if $boottime =~ /sec\s*=\s*(\d+)/;
chomp (my $currenttime = `date +%s`);
my $uptime = $currenttime - $boottime;
# Uptime conversion
my ($UYEAR, $UMONTH , $UDAY, $UHOUR, $UMIN, $USEC) = (gmtime ($uptime))[5,4,3,2,1,0];
# Write in ISO format
$uptime=sprintf "%02d-%02d-%02d %02d:%02d:%02d", ($UYEAR-70), $UMONTH, ($UDAY-1), $UHOUR, $UMIN, $USEC;
chomp(my $DeviceType =`uname -m`);
# TODO$h->{'CONTENT'}{'HARDWARE'}{'DESCRIPTION'} = [ "$DeviceType/$uptime" ];
$common->setHardware({ DESCRIPTION => "$DeviceType/$uptime" });
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic.pm 0000664 0000000 0000000 00000000120 14323200667 0023560 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic;
use strict;
sub run {}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/ 0000775 0000000 0000000 00000000000 14323200667 0023231 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Dmidecode.pm 0000664 0000000 0000000 00000000376 14323200667 0025452 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Dmidecode;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return unless -r "/dev/mem";
return unless $common->can_run("dmidecode");
1;
}
sub run {}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Dmidecode/ 0000775 0000000 0000000 00000000000 14323200667 0025106 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Dmidecode/Batteries.pm 0000664 0000000 0000000 00000004601 14323200667 0027367 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Dmidecode::Batteries;
use strict;
sub run {
my $params = shift;
my $common = $params->{common};
my $dmidecode = `dmidecode`; # TODO retrieve error
# some versions of dmidecode do not separate items with new lines
# so add a new line before each handle
$dmidecode =~ s/\nHandle/\n\nHandle/g;
my @dmidecode = split (/\n/, $dmidecode);
# add a new line at the end
push @dmidecode, "\n";
s/^\s+// for (@dmidecode);
my $flag;
my $location;
my $manufacturer;
my $manufacturedate;
my $serialnumber;
my $name;
my $chemistry;
my $designcapacity;
my $designvoltage;
my $sbdsversion;
my $maxerror;
my $oemspecific;
my $numslot;
foreach (@dmidecode) {
if (/dmi type 22,/i) { # beginning of Memory Device section
$flag = 1;
$numslot++;
} elsif ($flag && /^$/) { # end of section
$flag = 0;
$common->addBatteries({
LOCATION => $location,
MANUFACTURER => $manufacturer,
MANUFACTUREDATE => $manufacturedate,
SERIALNUMBER => $serialnumber,
NAME => $name,
CHEMISTRY => $chemistry,
DESIGNCAPACITY => $designcapacity,
DESIGNVOLTAGE => $designvoltage,
SBDSVERSION => $sbdsversion,
MAXERROR => $maxerror,
OEMSPECIFIC => $oemspecific,
});
$location = $manufacturer = $manufacturedate = $serialnumber = $name = $chemistry = $designcapacity = $designvoltage = $sbdsversion = $maxerror = $oemspecific = undef;
} elsif ($flag) { # in the section
$location = $1 if /^Location:\s*(\S+)/i;
$manufacturer = $1 if /^Manufacturer:\s*(.+)/i;
$manufacturedate = $1 if /^Manufacture Date:\s*(.+)/i;
$serialnumber = $1 if /^Serial Number:\s*(.+)/i;
$name = $1 if /^Name:\s*(.+)/i;
$chemistry = $1 if /^Chemistry:\s*(.+)/i;
$designcapacity = $1 if /^Design Capacity:\s*(.+)/i;
$designvoltage = $1 if /^Design Voltage:\s*(.+)/i;
$sbdsversion = $1 if /^SBDS Version:\s*(.+)/i;
$maxerror = $1 if /^Maximum Error:\s*(.+)/i;
$oemspecific = $1 if /^OEM-specific Information:\s*(.+)/i;
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Dmidecode/Bios.pm 0000664 0000000 0000000 00000005623 14323200667 0026346 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Dmidecode::Bios;
use strict;
sub run {
my $params = shift;
my $common = $params->{common};
# Parsing dmidecode output
# Using "type 0" section
my( $SystemSerial , $SystemModel, $SystemManufacturer,
$SystemVersion, $BiosManufacturer, $BiosVersion,
$BiosDate, $AssetTag, $MotherboardManufacturer,
$MotherboardModel, $MotherboardSerial, $Type );
#System DMI
$SystemManufacturer = `dmidecode -s system-manufacturer`;
$SystemModel = `dmidecode -s system-product-name`;
$SystemSerial = `dmidecode -s system-serial-number`;
$SystemVersion = `dmidecode -s system-version`;
$AssetTag = `dmidecode -s chassis-asset-tag`;
$Type = `dmidecode -s chassis-type`;
#Motherboard DMI
$MotherboardManufacturer = `dmidecode -s baseboard-manufacturer`;
$MotherboardModel = `dmidecode -s baseboard-product-name`;
$MotherboardSerial = `dmidecode -s baseboard-serial-number`;
#BIOS DMI
$BiosManufacturer = `dmidecode -s bios-vendor`;
$BiosVersion = `dmidecode -s bios-version`;
$BiosDate = `dmidecode -s bios-release-date`;
foreach my $info ( $SystemSerial , $SystemModel, $SystemManufacturer,
$SystemVersion, $BiosManufacturer, $BiosVersion,
$BiosDate, $AssetTag, $MotherboardManufacturer,
$MotherboardModel, $MotherboardSerial, $Type ) {
# Remove lines starting with #
$info =~ s/(\s*#.*\n)+//g;
# Remove error msg 'Invalid entry length (0). DMI table is broken! Stop.'
$info =~ s/Invalid.*//g;
# Remove break lines
$info =~ s/\n//g;
# Remove whitespaces at start/end
$info =~ s/^\s+|\s+$//g;
}
#System DMI
if ($SystemModel && $SystemManufacturer && $SystemManufacturer =~ /^LENOVO$/i && $SystemVersion =~ /^(Think|Idea|Yoga|Netfinity|Netvista|Intelli)/i) {
my $product_name = $SystemVersion;
$SystemVersion = $SystemModel;
$SystemModel = $product_name;
}
# If serial number is empty, assign mainboard serial (e.g Intel NUC)
if (!$SystemSerial) {
$SystemSerial = $MotherboardSerial;
}
# Some bioses don't provide a serial number so I check for CPU ID (e.g: server from dedibox.fr)
my @cpu;
if (!$SystemSerial || $SystemSerial =~ /^0+$/) {
@cpu = `dmidecode -t processor`;
for (@cpu){
if (/ID:\s*(.*)/i){
$SystemSerial = $1;
}
}
}
# Writing data
$common->setBios ({
ASSETTAG => $AssetTag,
SMANUFACTURER => $SystemManufacturer,
SMODEL => $SystemModel,
SSN => $SystemSerial,
BMANUFACTURER => $BiosManufacturer,
BVERSION => $BiosVersion,
BDATE => $BiosDate,
MMANUFACTURER => $MotherboardManufacturer,
MMODEL => $MotherboardModel,
MSN => $MotherboardSerial,
TYPE => $Type,
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Dmidecode/Memory.pm 0000664 0000000 0000000 00000007423 14323200667 0026722 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Dmidecode::Memory;
use strict;
sub run {
my $params = shift;
my $common = $params->{common};
my $dmidecode;
my @dmidecode;
my %dmidecode;
my $capacity;
my $speed;
my $type;
my $numslot;
my $serialnumber;
my $manufacturer;
my $caption;
my $description;
# DMI type 17
$dmidecode = `dmidecode -t 17`;
@dmidecode = split (/Handle\s/i, $dmidecode);
shift @dmidecode;
$numslot = 0;
foreach (@dmidecode) {
$capacity = $speed = $type = $serialnumber = $manufacturer = $caption = $description = 0;
$caption = $1 if /\s\sLocator:\s([\w\d_\-\s#]+)\n/i;
$speed = $1 if /Speed:\s([\w\d]+)/i;
$type = $1 if /Type:\s([\s\w]+)\n/i;
$description = $1 if /Type\sDetail:\s([\s\w]+)\n/i;
$manufacturer = $1 if /Manufacturer:\s([\w\d\-\_\s]+)\n/i;
$serialnumber = $1 if /Serial\sNumber:\s([\w\d\-\_\s]+)\n/i;
if (/Size:\s(\d+)\s(MB|GB|TB|MByte|GByte|TByte)/i) {
if($2 eq "MB" or $2 eq "MByte") {
$capacity = $1;
}
elsif($2 eq "GB" or $2 eq "GByte") {
$capacity = $1*1024;
}
elsif($2 eq "TB" or $2 eq "TByte") {
$capacity = $1*1024*1024;
}
}
if (/DMI type 17/i) {
$dmidecode{$numslot}{caption} = $caption ? $caption : "";
$dmidecode{$numslot}{description} = $description ? $description : "";
$dmidecode{$numslot}{speed} = $speed ? $speed : "";
$dmidecode{$numslot}{type} = $type ? $type : "";
$dmidecode{$numslot}{manufacturer} = $manufacturer ? $manufacturer : "";
$dmidecode{$numslot}{serialnumber} = $serialnumber ? $serialnumber : "";
$dmidecode{$numslot}{capacity} = $capacity ? $capacity : "";
$numslot++;
}
}
# DMI type 6 if type 17 is not available
if (!$numslot) {
$dmidecode = `dmidecode -t 6`; # TODO retrieve error
@dmidecode = split (/Handle\s/i, $dmidecode);
shift @dmidecode;
$numslot = 0;
foreach (@dmidecode) {
$capacity = $speed = $type = $caption = 0;
$caption = $1 if /Socket Designation:\s([\w\d_\-\s#]+)\n/i;
$capacity = $1 if /Installed\sSize:\s(\d+)/i;
$speed = $1 if /Speed:\s([\w\d]+)/i;
$type = $1 if /Type:\s([\s\w]+)\n/i;
if (/Size:\s(\d+)\s(MB|GB|TB|MByte|GByte|TByte)/i) {
if($2 eq "MB" or $2 eq "MByte") {
$capacity = $1;
}
elsif($2 eq "GB" or $2 eq "GByte") {
$capacity = $1*1024;
}
elsif($2 eq "TB" or $2 eq "TByte") {
$capacity = $1*1024*1024;
}
}
if (/DMI type 6/i) {
$dmidecode{$numslot}{caption} = $caption ? $caption : "";
$dmidecode{$numslot}{description} = $description ? $description : "";
$dmidecode{$numslot}{speed} = $speed ? $speed : "";
$dmidecode{$numslot}{type} = $type ? $type : "";
$dmidecode{$numslot}{capacity} = $capacity ? $capacity : "";
$numslot++;
}
}
}
foreach (sort {$a <=> $b} keys %dmidecode) {
$common->addMemory({
CAPACITY => $dmidecode{$_}{capacity},
SPEED => $dmidecode{$_}{speed},
TYPE => $dmidecode{$_}{type},
MANUFACTURER => $dmidecode{$_}{manufacturer},
SERIALNUMBER => $dmidecode{$_}{serialnumber},
NUMSLOTS => $_,
CAPTION => $dmidecode{$_}{caption},
DESCRIPTION => $dmidecode{$_}{description},
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Dmidecode/Ports.pm 0000664 0000000 0000000 00000002443 14323200667 0026556 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Dmidecode::Ports;
use strict;
sub run {
my $params = shift;
my $common = $params->{common};
my $dmidecode = `dmidecode`; # TODO retrieve error
# some versions of dmidecode do not separate items with new lines
# so add a new line before each handle
$dmidecode =~ s/\nHandle/\n\nHandle/g;
my @dmidecode = split (/\n/, $dmidecode);
# add a new line at the end
push @dmidecode, "\n";
s/^\s+// for (@dmidecode);
my $flag;
my $caption;
my $description;
my $name;
my $type;
foreach (@dmidecode) {
if (/dmi type 8,/i) {
$flag = 1;
} elsif ($flag && /^$/){ # end of section
$flag = 0;
$common->addPorts({
CAPTION => $caption,
DESCRIPTION => $description,
NAME => $name,
TYPE => $type,
});
$caption = $description = $name = $type = undef;
} elsif ($flag) {
$caption = $1 if /^external connector type\s*:\s*(.+)/i;
$description = $1 if /^internal connector type\s*:\s*(.+)/i;
$name = $1 if /^internal reference designator\s*:\s*(.+)/i;
$type = $1 if /^port type\s*:\s*(.+)/i;
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Dmidecode/Psu.pm 0000664 0000000 0000000 00000002121 14323200667 0026207 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Dmidecode::Psu;
use strict;
use warnings;
sub run {
my $params = shift;
my $common = $params->{common};
my $infos=$common->getDmidecodeInfos();
my $psu;
foreach my $info (@{$infos->{39}}) {
next if $info->{'Type'} && $info->{'Type'} eq 'Battery';
$psu->{NAME}=$1 if ($info =~ /Name:\s*(.*)/i);
$psu->{LOCATION}=$1 if ($info =~ /Location:\s*(.*)/i);
$psu->{STATUS}=$1 if ($info =~ /Status:\s*(.*)/i);
$psu->{SERIALNUMBER}=$1 if ($info =~ /Serial Number:\s*(.*)/i);
$psu->{PLUGGED}=$1 if ($info =~ /Plugged:\s*(.*)/i);
$psu->{HOTREPLACEABLE}=$1 if ($info =~ /Hot Replaceable:\s*(.*)/i);
$psu->{POWERMAX}=$1 if ($info =~ /Max Power Capacity:\s*(.*)/i);
$psu->{MANUFACTURER}=$1 if ($info =~ /Manufacturer:\s*(.*)/i);
$psu->{PARTNUMBER}=$1 if ($info =~ /Model Part Number:\s*(.*)/i);
next unless ($psu);
next unless ($psu->{'NAME'} || $psu->{'SERIALNUMBER'} || $psu->{'PARTNUMBER'});
$common->addPSU($psu);
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Dmidecode/Slots.pm 0000664 0000000 0000000 00000002351 14323200667 0026551 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Dmidecode::Slots;
use strict;
sub run {
my $params = shift;
my $common = $params->{common};
my $dmidecode = `dmidecode`;
# some versions of dmidecode do not separate items with new lines
# so add a new line before each handle
$dmidecode =~ s/\nHandle/\n\nHandle/g;
my @dmidecode = split (/\n/, $dmidecode);
# add a new line at the end
push @dmidecode, "\n";
s/^\s+// for (@dmidecode);
my $flag;
my $description;
my $designation;
my $name;
my $status;
foreach (@dmidecode) {
if (/dmi type 9,/i) {
$flag=1;
} elsif ($flag && /^$/) {
$flag=0;
$common->addSlot({
DESCRIPTION => $description,
DESIGNATION => $designation,
NAME => $name,
STATUS => $status,
});
$description = $designation = $name = $status = undef;
} elsif ($flag) {
$description = $1 if /^type\s*:\s*(.+)/i;
$designation = $1 if /^id\s*:\s*(.+)/i;
$name = $1 if /^designation\s*:\s*(.+)/i;
$status = $1 if /^current usage\s*:\s*(.+)/i;
};
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Dmidecode/UUID.pm 0000664 0000000 0000000 00000000722 14323200667 0026213 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Dmidecode::UUID;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return $common->can_run('dmidecode')
}
sub run {
my $params = shift;
my $common = $params->{common};
my $uuid;
$uuid = `dmidecode -s system-uuid`;
chomp($uuid);
$uuid =~ s/^#+\s+$//g;
$uuid =~ s/Invalid.*$//g;
$common->setHardware({
UUID => $uuid,
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Hostname.pm 0000664 0000000 0000000 00000001224 14323200667 0025344 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Hostname;
sub check {
my $params = shift;
my $common = $params->{common};
return 1 if $common->can_load ("Sys::Hostname");
return 1 if $common->can_run ("hostname");
0;
}
# Initialise the distro entry
sub run {
my $params = shift;
my $common = $params->{common};
my $hostname;
if ($common->can_load("Sys::Hostname")) {
$hostname = Sys::Hostname::hostname();
} else {
chomp ( $hostname = `hostname` ); # TODO: This is not generic.
}
$hostname =~ s/\..*//; # keep just the hostname
$common->setHardware ({NAME => $hostname});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Ipmi.pm 0000664 0000000 0000000 00000004402 14323200667 0024465 0 ustar 00root root 0000000 0000000 #
# OcsInventory agent - IPMI lan channel report
#
# Copyright (c) 2008 Jean Parpaillon
#
# The Intelligent Platform Management Interface (IPMI) specification
# defines a set of common interfaces to a computer system which system
# administrators can use to monitor system health and manage the
# system. The IPMI consists of a main controller called the Baseboard
# Management Controller (BMC) and other satellite controllers.
#
# The BMC can be fetched through client like OpenIPMI drivers or
# through the network. Though, the BMC hold a proper MAC address.
#
# This module reports the MAC address and, if any, the IP
# configuration of the BMC. This is reported as a standard NIC.
#
package Ocsinventory::Agent::Backend::OS::Generic::Ipmi;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run("ipmitool") && $common->can_load("Net::IP qw(:PROC)");
my @ipmitool = `ipmitool lan print 2> /dev/null`;
return unless @ipmitool;
}
# Initialise the distro entry
sub run {
my $params = shift;
my $common = $params->{common};
my $description;
my $ipaddress;
my $ipgateway;
my $ipmask;
my $ipsubnet;
my $macaddr;
my $status;
my $type;
foreach (`LANG=C ipmitool lan print 2> /dev/null`) {
if (/^IP Address\s+:\s+(\d+\.\d+\.\d+\.\d+)/) {
$ipaddress = $1;
}
if (/^Default Gateway IP\s+:\s+(\d+\.\d+\.\d+\.\d+)/) {
$ipgateway = $1;
}
if (/^Subnet Mask\s+:\s+(\d+\.\d+\.\d+\.\d+)/) {
$ipmask = $1;
}
if (/^MAC Address\s+:\s+([0-9a-f]{2}(:[0-9a-f]{2}){5})/) {
$macaddr = $1;
}
}
$description = 'bmc';
my $binip = &ip_iptobin ($ipaddress, 4);
my $binmask = &ip_iptobin ($ipmask, 4);
my $binsubnet = $binip & $binmask;
$ipsubnet = ip_bintoip($binsubnet, 4);
$status = 1 if $ipaddress != '0.0.0.0';
$type = 'Ethernet';
$common->addNetwork({
DESCRIPTION => $description,
IPADDRESS => $ipaddress,
IPDHCP => "",
IPGATEWAY => $ipgateway,
IPMASK => $ipmask,
IPSUBNET => $ipsubnet,
MACADDR => $macaddr,
STATUS => $status?"Up":"Down",
TYPE => $type,
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Lspci.pm 0000664 0000000 0000000 00000000276 14323200667 0024646 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Lspci;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("lspci")
}
sub run {}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Lspci/ 0000775 0000000 0000000 00000000000 14323200667 0024303 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Lspci/Controllers.pm 0000664 0000000 0000000 00000003457 14323200667 0027160 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Lspci::Controllers;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("lspci")
}
sub run {
my $params = shift;
my $common = $params->{common};
my $driver;
my $name;
my $manufacturer;
my $pciid;
my $pcislot;
my $type;
my $lspci_version;
my $command = "lspci -vvv 2>/dev/null";
#We get the current lspci version
`lspci --version` =~ m/lspci\sversion\s(\d+.*)/ ;
$lspci_version=$1;
$lspci_version = $common->convertVersion($lspci_version,3);
if ($lspci_version >= 224) { #More informations since version 2.2.4
$command = "lspci -vvv -nn 2>/dev/null";
}
foreach(`$command`){
if (/^(\S+)\s+(\w+.*?):\s(.*)/) {
$pcislot = $1;
$name = $2;
$manufacturer = $3;
if ($manufacturer =~ s/ \((rev \S+)\)//) {
$type = $1;
}
$manufacturer =~ s/\ *$//; # clean up the end of the string
$manufacturer =~ s/\s+\(prog-if \d+ \[.*?\]\)$//; # clean up the end of the string
if ($manufacturer =~ s/ \[([A-z\d]+:[A-z\d]+)\]$//) {
$pciid = $1;
}
}
if ($pcislot && /^\s+Kernel driver in use: (\w+)/) {
$driver = $1;
}
if ($pcislot && /^$/) {
$common->addController({
'DRIVER' => $driver,
'NAME' => $name,
'MANUFACTURER' => $manufacturer,
'PCIID' => $pciid,
'PCISLOT' => $pcislot,
'TYPE' => $type,
});
$driver = $name = $pciid = $pcislot = $manufacturer = $type = undef;
}
}
}
1
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Lspci/Modems.pm 0000664 0000000 0000000 00000000670 14323200667 0026070 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Lspci::Modems;
use strict;
sub run {
my $params = shift;
my $common = $params->{common};
foreach(`lspci`){
if (/modem/i && /\d+\s(.+):\s*(.+)$/){
my $name = $1;
my $description = $2;
$common->addModems({
'DESCRIPTION' => $description,
'NAME' => $name,
});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Lspci/Sounds.pm 0000664 0000000 0000000 00000000641 14323200667 0026115 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Lspci::Sounds;
use strict;
sub run {
my $params = shift;
my $common = $params->{common};
foreach(`lspci`){
if (/audio/i && /^\S+\s([^:]+):\s*(.+?)(?:\(([^()]+)\))?$/i){
$common->addSound({
'DESCRIPTION' => $3,
'MANUFACTURER' => $2,
'NAME' => $1,
});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Lspci/Videos.pm 0000664 0000000 0000000 00000002004 14323200667 0026066 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Lspci::Videos;
use strict;
my $memory;
my $chipset;
my $name;
sub run {
my $params = shift;
my $common = $params->{common};
foreach(`lspci`){
if(/graphics|vga|video|display/i && /^([0-9a-f][0-9a-f]:[0-9a-f][0-9a-f].[0-9a-f])\s([^:]+):\s*(.+?)(?:\(([^()]+)\))?$/i){
my $slot = $1;
$chipset = $2;
$name = $3;
if (defined $slot) {
my @detail = `lspci -v -s $slot 2>/dev/null`;
$memory = 0;
foreach my $m (@detail) {
if ($m =~ /.*Memory.*\s+\(.*-bit,\sprefetchable\)\s\[size=(\d*)M\]/) {
$memory += $1;
}
}
# Don't record zero memory
$memory = undef if $memory == 0;
}
$common->addVideo({
'CHIPSET' => $chipset,
'NAME' => $name,
'MEMORY' => $memory,
});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Lsusb.pm 0000664 0000000 0000000 00000000276 14323200667 0024664 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Lsusb;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("lsusb")
}
sub run {}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Lsusb/ 0000775 0000000 0000000 00000000000 14323200667 0024321 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Lsusb/Usb.pm 0000664 0000000 0000000 00000003245 14323200667 0025414 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Lsusb::Usb;
use strict;
use Config;
use Data::Dumper;
my $vendor;
my $product;
my $interface;
my $bus;
my $device;
my $serial;
my $protocol;
my $id;
sub run {
my $params = shift;
my $common = $params->{common};
foreach (`lsusb`) {
if (/^Bus\s+(\d+)\sDevice\s(\d*):\sID\s(\d+):(\d+)*/i) {
next if (grep (/$4/,qw(0001 0002 0024)));
$bus=$1;
$device=$2;
#if (defined $bus && defined $device) {
my @detail = `lsusb -v -s $bus:$device 2>/dev/null`;
foreach my $d (@detail) {
if ($d =~ /^\s*iManufacturer\s*\d+\s*(.*)/i) {
$vendor = $1;
} elsif ($d =~ /^\s*iProduct\s*\d+\s*(.*)/i) {
$product = $1;
} elsif ($d =~ /^\s*iSerial\s*\d+\s(.*)/i) {
$serial = $1;
#} elsif ($d =~ /^\s*bInterfaceProtocol\s*\d\s(.*)/i) {
} elsif ($d =~ /^\s*bInterfaceClass\s*\d+\s*(.*)/i) {
#$protocol = $1 unless defined $protocol || $1 eq 'None';
$protocol = $1;
#} elsif ($d =~ /^\s*iInterface\s*\d\s(\w+)\s(.*)/i){
} elsif ($d =~ /^\s*bInterfaceSubClass\s*\d+\s(.*)/i){
$interface = $1;
}
}
# Add information to $current
$common->addUsb({
DESCRIPTION => $product,
INTERFACE => $interface,
MANUFACTURER => $vendor,
SERIAL => $serial,
TYPE => $protocol,
});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/OS.pm 0000664 0000000 0000000 00000001340 14323200667 0024106 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::OS;
use strict;
use warnings;
sub check {
my $params = shift;
my $common = $params->{common};
if ($common->can_run("stat")) {
return 1;
} else {
return 0;
}
}
# Initialise the distro entry
sub run {
my $params = shift;
my $common = $params->{common};
my $installdate;
my $idate;
if ($^O =~ /linux/) {
$idate=`stat -c %W /`;
} elsif (($^O =~ /bsd/) or ($^O =~ /Darwin/)) {
$idate=`stat -f %m /`;
}
my ($day,$month,$year)=(localtime($idate))[3,4,5];
$installdate=sprintf "%02d-%02d-%02d",($year+1900),$month,$day;
$common->setHardware({
INSTALLDATE => $installdate
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Packaging.pm 0000664 0000000 0000000 00000000411 14323200667 0025447 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Packaging;
use strict;
sub check {
my $params = shift;
# Do not run an package inventory if there is the --nosoftware parameter
return if ($params->{config}->{nosoftware});
1;
}
sub run{}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Packaging/ 0000775 0000000 0000000 00000000000 14323200667 0025115 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Packaging/AppImage.pm 0000664 0000000 0000000 00000001001 14323200667 0027126 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Packaging::AppImage;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("updatedb")
}
sub run {
my $params = shift;
my $common = $params->{common};
foreach(`locate -i "*.appimage"`){
/^(\/)(\S+)(\/)(\S+)/;
my $name = $4;
my $publisher = "AppImage";
$common->addSoftware({
'NAME' => $name,
'PUBLISHER' => $publisher
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Packaging/BSDpkg.pm 0000664 0000000 0000000 00000002076 14323200667 0026572 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Packaging::BSDpkg;
sub check {
my $params = shift;
my $common = $params->{common};
return if ( `uname -rs` =~ /SunOS 5.11/ );
$common->can_run("pkg") || $common->can_run("pkg_info")
}
sub run {
my $params = shift;
my $common = $params->{common};
if ($common->can_run("pkg")) {
foreach(`pkg info`){
/^(\S+)-(\d+\S*)\s+(.*)/;
my $name = $1;
my $version = $2;
my $comments = $3;
$common->addSoftware({
'COMMENTS' => $comments,
'NAME' => $name,
'VERSION' => $version
});
}
} elsif ($common->can_run("pkg_info")) {
foreach(`pkg_info`){
/^(\S+)-(\d+\S*)\s+(.*)/;
my $name = $1;
my $version = $2;
my $comments = $3;
$common->addSoftware({
'COMMENTS' => $comments,
'NAME' => $name,
'VERSION' => $version
});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Packaging/ByHand.pm 0000664 0000000 0000000 00000003211 14323200667 0026615 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Packaging::ByHand;
#How does it work ?
#
#Create a directory called software in place where you have your
#"modules.conf" file.
#Put your scripts in this directory.
#The scripts have to write on the STDIO with the following format :
#publisher#software#version#comment
#
use strict;
use warnings;
sub check {
return(1);
1;
}
sub run() {
my $params = shift;
my $common = $params->{common};
my $ligne;
my $soft;
my $comm;
my $version;
my $file;
my $vendor;
my $commentaire;
my @dots;
#if (!$file || !-d $file) {
foreach (@{$common->{config}{etcdir}}) {
$file = $_.'/softwares';
last if -d $file;
}
#}
my $logger = $params->{logger};
if ( opendir(my $dh, $file) ){
@dots = readdir($dh);
foreach (@dots) {
if ( -f $file."/".$_ ){
$comm = $file."/".$_;
$logger->debug("Running appli detection scripts from ".$comm);
foreach (`$comm`){
$ligne = $_;
chomp($ligne);
($vendor,$soft,$version,$commentaire) = split(/\#/,$ligne);
$common->addSoftware ({
'PUBLISHER' => $vendor,
'NAME' => $soft,
'VERSION' => $version,
'FILESIZE' => "",
'COMMENTS' => $commentaire,
'FROM' => 'ByHand'
});
}
}
}
closedir $dh;
}
1;
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Packaging/Deb.pm 0000664 0000000 0000000 00000004372 14323200667 0026153 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Packaging::Deb;
use strict;
use warnings;
use File::Basename;
use File::stat;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("dpkg") }
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my $size;
my $key;
my $value;
my %statinfo;
my @infos;
# List of files from which installation date will be extracted
my @listfile=glob('"/var/lib/dpkg/info/*.list"');
foreach my $file_list (@listfile){
my $stat=stat($file_list);
my ($year,$month,$day,$hour,$min,$sec)=(localtime($stat->mtime))[5,4,3,2,1,0];
$value=sprintf "%02d/%02d/%02d %02d:%02d:%02d",($year+1900),$month,$day,$hour,$min,$sec;
$key=fileparse($file_list, ".list");
$key =~ s/(\s+):.+/$1/;
$statinfo{$key}=$value;
}
# Use binary:Package to see all packages (amd64,deb) with dpkg > 1162
my $ver=`dpkg --list dpkg | tail -n 1 | cut -d" " -f14`;
$ver=~chomp($ver);
my $vers=$common->convertVersion($ver,4);
if ($vers > 1162 ){
@infos=`dpkg-query --show --showformat='\${binary:Package}---\${Architecture}---\${Version}---\${Installed-Size}---\${Status}---\${Homepage}---\${Description}\n'`;
} else {
@infos=`dpkg-query --show --showformat='\${Package}---\${Architecture}---\${Version}---\${Installed-Size}---\${Status}---\${Homepage}---\${Description}\n'`;
}
foreach my $line (@infos) {
next if $line =~ /^ /;
chomp $line;
my @deb=split("---",$line);
if ($deb[4] && $deb[4] !~ / installed/) {
$logger->debug("Skipping $deb[0] package as not installed, status='$deb[4]'");
next;
}
$key=$deb[0];
if (exists $statinfo{$key}) {
$common->addSoftware ({
'NAME' => $deb[0],
'ARCHITECTURE' => $deb[1],
'VERSION' => $deb[2],
'FILESIZE' => ( $deb[3] || 0 ) * 1024,
'PUBLISHER' => $deb[5],
'INSTALLDATE' => $statinfo{$key},
'COMMENTS' => $deb[6],
'FROM' => 'deb'
});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Packaging/Flatpak.pm 0000664 0000000 0000000 00000001437 14323200667 0027042 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Packaging::Flatpak;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run("flatpak");
}
sub run {
my $params = shift;
my $common = $params->{common};
if ($common->can_run("flatpak list")) {
foreach(`flatpak list`){
/(\S+)(\/)(\S+)(\/)(\S+)\s+(\S+)/;
my $name = $1;
my $version = $5;
my $publisher = "Flatpak package";
my $comments = $6;
$common->addSoftware({
'COMMENTS' => $comments,
'NAME' => $name,
'PUBLISHER' => $publisher,
'VERSION' => $version
});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Packaging/Gentoo.pm 0000664 0000000 0000000 00000002276 14323200667 0026715 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Packaging::Gentoo;
use strict;
use warnings;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("equery")
}
sub run {
my $params = shift;
my $common = $params->{common};
# TODO: This had been rewrite from the Linux agent _WITHOUT_ being checked!
# New format for listing softwares with equery command (equery 0.3.0.5)
# Older version don't run with these options
my $equery_vers = `equery --version ` =~ /.*\((.*)\).*/;
$equery_vers = $1;
my ($major,$minor)=$equery_vers=~/(\d+)\.(\d+)\.\d+/;
if ($minor ge 3) {
foreach (`equery list --format='\$cp \$fullversion' '*'`){
if (/^(.*) (.*)/) {
$common->addSoftware({
'NAME' => $1,
'VERSION' => $2,
});
}
}
} else {
# Old version of Gentoo
foreach (`equery list -i`){
if (/^([a-z]\w+-\w+\/\.*)-([0-9]+.*)/) {
$common->addSoftware({
'NAME' => $1,
'VERSION' => $2,
});
}
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Packaging/Pacman.pm 0000664 0000000 0000000 00000000752 14323200667 0026656 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Packaging::Pacman;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("/usr/bin/pacman")
}
sub run {
my $params = shift;
my $common = $params->{common};
foreach(`/usr/bin/pacman -Q`){
/^(\S+)\s+(\S+)/;
my $name = $1;
my $version = $2;
$common->addSoftware({
'NAME' => $name,
'VERSION' => $version
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Packaging/RPM.pm 0000664 0000000 0000000 00000003124 14323200667 0026111 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Packaging::RPM;
use strict;
use warnings;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run("rpm");
# Some time rpm is a wrapper or an alias for another
`rpm --version 2>&1`;
return if ($? >> 8)!=0;
1;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my @date;
my @list;
my $buff;
foreach (`rpm -qa --queryformat "%{NAME} --%{ARCH}-- %{VERSION}-%{RELEASE} --%{INSTALLTIME}-- --%{SIZE}-- --%{VENDOR}-- %{SUMMARY}\n--\n" 2>/dev/null`) {
if (! /^--/) {
chomp;
$buff .= $_;
} elsif ($buff =~ s/^(.*)\s+--(.*)--\s+(\S+)\s+--(.*)--\s+--(.*)--\s+--(.*)--\s+(.*)//) {
my ($name,$arch,$version,$installdate,$filesize,$vendor,$comments) = ( $1,$2,$3,$4,$5,$6,$7 );
@date = localtime($installdate);
$installdate = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $date[5] + 1900, $date[4] + 1, $date[3], $date[2], $date[1], $date[0]);
$common->addSoftware({
'NAME' => $name,
'ARCHITECTURE' => $arch,
'VERSION' => $version,
'INSTALLDATE' => $installdate,
'FILESIZE' => $filesize,
'COMMENTS' => $comments,
'PUBLISHER' => $vendor,
'FROM' => 'rpm'
});
} else {
$logger->debug("Should never go here!");
$buff = '';
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Packaging/Snap.pm 0000664 0000000 0000000 00000001607 14323200667 0026360 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Packaging::Snap;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run("snap");
}
sub run {
my $params = shift;
my $common = $params->{common};
if ($common->can_run("snap list")) {
my $i = 0;
foreach(`snap list`){
/^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/;
if($i >= 1) {
my $name = $1;
my $version = $2;
my $publisher = $5;
my $comments = "Snap package";
$common->addSoftware({
'COMMENTS' => $comments,
'NAME' => $name,
'PUBLISHER' => $publisher,
'VERSION' => $version
});
}
$i++;
}
}
}
1; UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Printers/ 0000775 0000000 0000000 00000000000 14323200667 0025037 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Printers/Cups.pm 0000664 0000000 0000000 00000002404 14323200667 0026307 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Printers::Cups;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
# If we are on a MAC, Mac::SysProfile will do the job
return if -r '/usr/sbin/system_profiler';
return unless $common->can_load("Net::CUPS") && $Net::CUPS::VERSION >= 0.60;
return 1;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $cups = Net::CUPS->new();
my @destinations = $cups->getDestinations();
my $printer;
my $description;
my $port;
my $driver;
foreach (@destinations) {
$printer = $_->getName() unless $printer;
$description = $_->getDescription() unless $description;
$port = $_->getUri() unless $port;
$driver = $_->getOptionValue("printer-make-and-model") unless $driver;
# Just grab the default printer, if I use getDestinations, CUPS
# returns all the printer of the local subnet (if it can)
# TODO There is room for improvement here
$common->addPrinter({
NAME => $printer,
DESCRIPTION => $description,
PORT => $port,
DRIVER => $driver
});
$printer = $description = $port = $driver = undef;
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Repository.pm 0000664 0000000 0000000 00000000133 14323200667 0025743 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Repository;
use strict;
sub run {}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Repository/ 0000775 0000000 0000000 00000000000 14323200667 0025410 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Repository/BSD.pm 0000664 0000000 0000000 00000003477 14323200667 0026371 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Repository::BSD;
use strict;
use warnings;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run("pkg");
}
my $repo_name;
my $repo_baseurl;
my $repo_priority;
my $repo_mirror_type;
my $repo_signature_type;
my $repo_fingerprints;
my $repo_enable;
sub run {
my $params = shift;
my $common = $params->{common};
if ($^O eq 'freebsd') {
foreach my $line (`LANG=C pkg -vv 2>/dev/null`){
next if ($line =~ /^Repositories:/i);
if ($line =~ /^\s+(.*):\s\{/i){
$repo_name = $1;
} elsif ($line =~ /url\s+:\s\"(.*)\"/i) {
$repo_baseurl = $1;
} elsif ($line =~ /enabled\s+:\s(.*)\,/i){
$repo_enable = $1;
} elsif ($line =~ /priority\s+:\s(.*)\,/i) {
$repo_priority = $1;
} elsif ($line =~ /Mirror_type\s+:\s\"(.*)\"\,/i){
$repo_mirror_type = $1;
} elsif ($line =~ /signature_type\s+:\s\"(.*)\"\,/i){
$repo_signature_type = $1;
} elsif ($line =~ /fingerprints\s+:\s\"(.*)\"/i){
$repo_fingerprints = $1;
}
if ($line =~ /^ \}$/) {
$common->addRepo({
BASEURL => $repo_baseurl,
NAME => $repo_name,
ENABLED => $repo_enable,
PRIORITY => $repo_priority,
MIRROR => $repo_mirror_type,
SIGNATURE => $repo_signature_type,
FINGERPRINTS => $repo_fingerprints,
});
$repo_name = $repo_baseurl = $repo_enable = $repo_priority = $repo_mirror_type = $repo_signature_type = $repo_fingerprints = undef;
}
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Repository/CentOS.pm 0000664 0000000 0000000 00000004460 14323200667 0027105 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Repository::CentOS;
use strict;
use warnings;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run("yum");
}
my $repo_name;
my $repo_baseurl;
my $repo_filename;
my $repo_pkgs;
my $repo_rev;
my $repo_size;
my $repo_tag;
my $repo_updated;
my $repo_mirrors;
my $repo_expire;
my $repo_exclude;
my $repo_excluded;
my $repo_metalink;
sub run {
my $params = shift;
my $common = $params->{common};
my @repository=`LANG=C yum -v repolist 2>/dev/null`;
push @repository, "\n";
for (my $i=0;$i<$#repository;$i++){
my $line=$repository[$i];
if ($line =~ /^$/ && $repo_name && $repo_filename) {
$common->addRepo({
BASEURL => $repo_baseurl,
EXCLUDE => $repo_exclude,
EXCLUDED => $repo_excluded,
EXPIRE => $repo_expire,
FILENAME => $repo_filename,
MIRRORS => $repo_mirrors,
NAME => $repo_name,
PKGS => $repo_pkgs,
REVISION => $repo_rev,
SIZE => $repo_size,
TAG => $repo_tag,
UPDATED => $repo_updated,
});
$repo_name = $repo_baseurl = $repo_filename = $repo_pkgs = $repo_size = $repo_tag = $repo_updated = $repo_mirrors = $repo_expire = $repo_exclude = $repo_excluded = $repo_rev = $repo_metalink = undef;
}
$repo_name = $1 if ($line =~ /^Repo-name\s+:\s(.*)/i);
$repo_baseurl = $1 if ($line =~ /^Repo-baseurl\s+:\s(.*)/i);
$repo_mirrors = $1 if ($line =~ /^Repo-mirrors\s+:\s(.*)/i);
$repo_filename = $1 if ($line =~ /^Repo-filename:\s(.*)/i);
$repo_pkgs = $1 if ($line =~ /^Repo-pkgs\s+:\s(.*)/i);
$repo_rev = $1 if ($line =~ /^Repo-revision:\s(.*)/i);
$repo_size = $1 if ($line =~ /^Repo-size\s+:\s(.*)/i);
$repo_tag = $1 if ($line =~ /^Repo-tags\s+:\s(.*)/i);
$repo_updated = $1 if ($line =~ /^Repo-updated\s+:\s(.*)/i);
$repo_exclude = $1 if ($line =~ /^Repo-exclude\s+:\s(.*)/i);
$repo_excluded = $1 if ($line =~ /^Repo-excluded\s+:\s(.*)/i);
$repo_expire = $1 if ($line =~ /^Repo-expire\s+:\s(.*)/i);
$repo_metalink =$1 if ($line =~ /^Repo-metalink\s+:\s(.*)/i);
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Repository/Debian.pm 0000664 0000000 0000000 00000001613 14323200667 0027131 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Repository::Debian;
use strict;
use warnings;
sub check{
my $params = shift;
my $common = $params->{common};
return unless $common->can_run("apt-cache");
}
sub run{
my $params = shift;
my $common = $params->{common};
my ($repo_name, $repo_baseurl);
my @repository=`apt-cache policy | grep -i http | awk {'print \$2 " " \$3'} | sort -u`;
push @repository, "\n";
for (my $i=0;$i<$#repository;$i++){
my $line=$repository[$i];
$repo_name=$1 if ($line =~ /\/([^\/]*)\n$/);
$repo_baseurl=$1 if ($line =~ /^(\S*)\h/);
if ($line =~ /(^.*$)/ && $repo_name && $repo_baseurl){
$common->addRepo({
NAME => $repo_name,
BASEURL => $repo_baseurl,
});
$repo_name = $repo_baseurl = undef;
}
#$repo_name=$1 if ($line =~ /.*\s(\w-?\/\w)/);
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Repository/Rhel.pm 0000664 0000000 0000000 00000003630 14323200667 0026642 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Repository::Rhel;
use strict;
use warnings;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run("dnf");
}
my $repo_name;
my $repo_baseurl;
my $repo_filename;
my $repo_pkgs;
my $repo_rev;
my $repo_size;
my $repo_expire;
my $repo_updated;
my $repo_lastupdated;
my $repo_mirrors;
sub run {
my $params = shift;
my $common = $params->{common};
my @repository=`LANG=C dnf -v repolist 2>/dev/null`;
for (my $i=0;$i<$#repository;$i++){
my $line=$repository[$i];
if ($line =~ /^$/ && $repo_name && $repo_filename) {
$common->addRepo({
BASEURL => $repo_baseurl,
FILENAME => $repo_filename,
NAME => $repo_name,
PKGS => $repo_pkgs,
REVISION => $repo_rev,
SIZE => $repo_size,
UPDATED => $repo_updated,
LASTUPDATED => $repo_lastupdated,
EXPIRE => $repo_expire,
MIRRORS => $repo_mirrors,
});
$repo_name = $repo_expire = $repo_baseurl = $repo_filename = $repo_pkgs = $repo_rev = $repo_size = $repo_mirrors = $repo_updated = $repo_lastupdated = undef;
}
$repo_name=$1 if ($line =~ /^Repo-name\s+:\s(.*)/i);
$repo_baseurl=$1 if ($line =~ /^Repo-baseurl\s+:\s(.*)/i);
$repo_filename=$1 if ($line =~ /^Repo-filename:\s(.*)/i);
$repo_pkgs=$1 if ($line =~ /^Repo-pkgs\s+:\s(.*)/i);
$repo_rev=$1 if ($line =~ /^Repo-revision\s+:\s(.*)/i);
$repo_size=$1 if ($line =~ /^Repo-size\s+:\s(.*)/i);
$repo_expire=$1 if ($line =~ /^Repo-expire\s+:\s(.*)/i);
$repo_updated=$1 if ($line =~ /^Repo-updated\s+:\s(.*)/i);
$repo_lastupdated=$1 if ($line =~ /Updated\s+:\s(.*)/i);
$repo_mirrors=$1 if ($line =~ /^Repo-metalink\s+:\s(.*)/i);
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Repository/SuSE.pm 0000664 0000000 0000000 00000001434 14323200667 0026567 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Repository::SuSE;
use strict;
use warnings;
use Data::Dumper;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run("zypper");
}
sub run {
my $params = shift;
my $common = $params->{common};
my @repository=`LANG=C zypper lr -Ed 2>/dev/null`;
for (my $i=0;$i<=$#repository;$i++){
my $line=$repository[$i];
next if ($line =~ /^#/);
next if ($line =~ /^-/);
my ($num,$alias,$name,$enabled,$gpg,$refresh,$priority,$type,$url)=split('\|',$line);
$url =~ s/\s+//g;
$name =~ s/^\s+//;
$name =~ s/\s+$//;
$common->addRepo({
BASEURL => $url,
NAME => $name,
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Screen.pm 0000664 0000000 0000000 00000014432 14323200667 0025012 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Screen;
use strict;
use utf8;
use Parse::EDID;
sub haveExternalUtils {
my $common = shift;
return $common->can_run("monitor-get-edid-using-vbe") || $common->can_run("monitor-get-edid") || $common->can_run("get-edid");
}
sub check {
my $params = shift;
my $common = $params->{common};
return unless -d "/sys/devices" || haveExternalUtils($common);
1;
}
sub _getManufacturerFromCode {
my $code = shift;
my $h = {
"ACR" => "Acer America Corp.",
"ACT" => "Targa",
"ADI" => "ADI Corporation http://www.adi.com.tw",
"AOC" => "AOC International (USA) Ltd.",
"API" => "Acer America Corp.",
"APP" => "Apple Computer, Inc.",
"ART" => "ArtMedia",
"AST" => "AST Research",
"AMW" => "AMW",
"AUO" => "AU Optronics Corporation",
"BMM" => "BMM",
"BNQ" => "BenQ Corporation",
"BOE" => "BOE Display Technology",
"CPL" => "Compal Electronics, Inc. / ALFA",
"CPQ" => "COMPAQ Computer Corp.",
"CPT" => "Chunghwa Picture Tubes, Ltd.",
"CTX" => "CTX - Chuntex Electronic Co.",
"DEC" => "Digital Equipment Corporation",
"DEL" => "Dell Computer Corp.",
"DPC" => "Delta Electronics, Inc.",
"DWE" => "Daewoo Telecom Ltd",
"ECS" => "ELITEGROUP Computer Systems",
"ENC" => "EIZO",
"EIZ" => "EIZO",
"EPI" => "Envision Peripherals, Inc.",
"FCM" => "Funai Electric Company of Taiwan",
"FUJ" => "Fujitsu",
"FUS" => "Fujitsu Siemens",
"GSM" => "LG Electronics Inc. (GoldStar Technology, Inc.)",
"GWY" => "Gateway 2000",
"HEI" => "Hyundai Electronics Industries Co., Ltd.",
"HIQ" => "Hyundai ImageQuest",
"HIT" => "Hitachi",
"HSD" => "Hannspree Inc",
"HSL" => "Hansol Electronics",
"HTC" => "Hitachi Ltd. / Nissei Sangyo America Ltd.",
"HWP" => "Hewlett Packard",
"IBM" => "IBM PC Company",
"ICL" => "Fujitsu ICL",
"IFS" => "InFocus",
"IQT" => "Hyundai",
"IVM" => "Idek Iiyama North America, Inc.",
"KFC" => "KFC Computek",
"LEN" => "Lenovo",
"LGD" => "LG Display",
"LKM" => "ADLAS / AZALEA",
"LNK" => "LINK Technologies, Inc.",
"LPL" => "LG Philips",
"LTN" => "Lite-On",
"MAG" => "MAG InnoVision",
"MAX" => "Maxdata Computer GmbH",
"MEI" => "Panasonic Comm. & Systems Co.",
"MEL" => "Mitsubishi Electronics",
"MIR" => "Miro Computer Products AG",
"MTC" => "MITAC",
"MS_" => "Panasonic",
"NAN" => "NANAO",
"NEC" => "NEC Technologies, Inc.",
"NVD" => "Fujitsu",
"NOK" => "Nokia",
"OQI" => "OPTIQUEST",
"PBN" => "Packard Bell",
"PCK" => "Daewoo",
"PDC" => "Polaroid",
"PGS" => "Princeton Graphic Systems",
"PHL" => "Philips Consumer Electronics Co.",
"POS" => "Positivo Tecnologia S.A.",
"PRT" => "Princeton",
"PTS" => "ProView/EMC/PTS YakumoTFT17SL",
"REL" => "Relisys",
"SAM" => "Samsung",
"SMI" => "Smile",
"SMC" => "Samtron",
"SNI" => "Siemens Nixdorf",
"SNY" => "Sony Corporation",
"SPT" => "Sceptre",
"SRC" => "Shamrock Technology",
"STN" => "Samtron",
"STP" => "Sceptre",
"TAT" => "Tatung Co. of America, Inc.",
"TOS" => "Toshiba",
"TRL" => "Royal Information Company",
"TSB" => "Toshiba, Inc.",
"UNM" => "Unisys Corporation",
"VSC" => "ViewSonic Corporation",
"WTC" => "Wen Technology",
"ZCM" => "Zenith Data Systems",
"___" => "Targa" };
return $h->{$code} if (exists ($h->{$code}) && $h->{$code});
return "Unknown manufacturer code ".$code;
}
sub getEdid {
my $raw_edid;
my $port = $_[0];
# Mandriva
$raw_edid = `monitor-get-edid-using-vbe --port $port 2>/dev/null`;
# Since monitor-edid 1.15, it's possible to retrieve EDID information
# through DVI link but we need to use monitor-get-edid
if (!$raw_edid) {
$raw_edid = `monitor-get-edid --vbe-port $port 2>/dev/null`;
}
if (!$raw_edid) {
foreach (1..5) { # Sometime get-edid return an empty string...
$raw_edid = `get-edid 2>/dev/null`;
last if (length($raw_edid) == 128 || length($raw_edid) == 256);
}
}
return unless (length($raw_edid) == 128 || length($raw_edid) == 256);
return $raw_edid;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my $raw_perl = 1;
my $verbose;
my $MonitorsDB;
my $base64;
my $uuencode;
my %found;
my @edid_list;
# first check sysfs if there are edid entries
for my $file(split(/\0/,`find /sys/devices -wholename '*/card*/edid' -print0`)) {
open(my $sys_edid_fd,'<',$file);
my $raw_edid = do { local $/; <$sys_edid_fd> };
if (length($raw_edid) == 128 || length($raw_edid) == 256 ) {
push @edid_list, $raw_edid;
}
}
# if not fall back to the old method
if (!@edid_list && haveExternalUtils($common)) {
for my $port(0..20){
my $raw_edid = getEdid($port);
if ($raw_edid){
if (length($raw_edid) == 128 || length($raw_edid) == 256) {
push @edid_list, $raw_edid;
}
}
}
}
for my $raw_edid(@edid_list) {
my $edid = parse_edid($raw_edid);
if (my $err = check_parsed_edid($edid)) {
$logger->debug("check failed: bad edid: $err");
}
my $caption = $edid->{monitor_name};
$caption =~ s/[^ -~].*$//;
my $description = $edid->{week}."/".$edid->{year};
my $manufacturer = _getManufacturerFromCode($edid->{manufacturer_name});
my $serial = $edid->{serial_number};
if (!exists $found{$serial}) {
$found{$serial} = 1;
eval "use MIME::Base64;";
$base64 = encode_base64($raw_edid) if !$@;
if ($common->can_run("uuencode")) {
chomp($uuencode = `echo $raw_edid|uuencode -`);
if (!$base64) {
chomp($base64 = `echo $raw_edid|uuencode -m -`);
}
}
$common->addMonitor ({
BASE64 => $base64,
CAPTION => $caption,
DESCRIPTION => $description,
MANUFACTURER => $manufacturer,
SERIAL => $serial,
UUENCODE => $uuencode,
});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Generic/Users.pm 0000664 0000000 0000000 00000006564 14323200667 0024703 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Generic::Users;
use strict;
use warnings;
sub check {
my $params = shift;
my $common = $params->{common};
# Useless check for a posix system i guess
my @who = `who 2>/dev/null`;
my @last = `last -n 1 2>/dev/null`;
if (($common->can_read("/etc/passwd") && $common->can_read("/etc/group")) || @who || @last ) {
return 1;
} else {
return 0;
}
}
# Initialise the distro entry
sub run {
my $params = shift;
my $common = $params->{common};
my %users;
# Logged on users
for (`who`){
my $user = $1 if /^(\S+)./;
$common->addUser ({ LOGIN => $user });
}
# Local users
foreach my $user (_getLocalUsers()) {
push @{$users{$user->{GID}}}, $user->{LOGIN};
#delete $user->{GID};
$common->addLocalUser({
LOGIN => $user->{LOGIN},
ID_USER => $user->{ID_USER},
GID => $user->{GID},
NAME => $user->{NAME},
HOME => $user->{HOME},
SHELL => $user->{SHELL}
});
}
# Local groups with members
foreach my $group (_getLocalGroups()) {
push @{$group->{MEMBER}}, @{$users{$group->{ID_GROUP}}} if $users{$group->{ID_GROUP}};
my $group_member = join ',', @{$group->{MEMBER}};
$common->addLocalGroup({
ID_GROUP => $group->{ID_GROUP},
NAME => $group->{NAME},
MEMBER => $group_member
});
}
# last logged user
$common->setHardware(_getLast());
}
sub _getLocalUsers{
open(my $fh, '<:encoding(UTF-8)', "/etc/passwd") or warn;
my @userinfo=<$fh>;
close($fh);
my @users;
foreach my $line (@userinfo){
next if $line =~ /^#/;
next if $line =~ /^[+-]/; # old format for external inclusion
chomp $line;
my ($login, undef, $uid, $gid, $gecos, $home, $shell) = split(/:/, $line);
push @users, {
LOGIN => $login,
ID_USER => $uid,
GID => $gid,
NAME => $gecos,
HOME => $home,
SHELL => $shell,
};
}
return @users;
}
sub _getLocalGroups {
open(my $fh, '<:encoding(UTF-8)', "/etc/group") or warn;
my @groupinfo=<$fh>;
close($fh);
my @groups;
foreach my $line (@groupinfo){
next if $line =~ /^#/;
chomp $line;
my ($name, undef, $gid, $members) = split(/:/, $line);
my @members = split(/,/, $members);
push @groups, {
ID_GROUP => $gid,
NAME => $name,
MEMBER => \@members,
};
}
return @groups;
}
sub _getLast {
my ($lastuser,$lastlogged);
my @info=`last -n 50`;
foreach my $last (@info) {
chomp $last;
next if $last =~ /^(reboot|shutdown)/;
my @last = split(/\s+/, $last);
next unless (@last);
$lastuser = shift @last or next;
# Found time on column starting as week day
shift @last while ( @last > 3 && $last[0] !~ /^mon|tue|wed|thu|fri|sat|sun/i );
$lastlogged = @last > 3 ? "@last[0..3]" : undef;
last;
}
return unless $lastuser;
return {
LASTLOGGEDUSER => $lastuser,
DATELASTLOGGEDUSER => $lastlogged
};
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/HPUX.pm 0000664 0000000 0000000 00000001177 14323200667 0023005 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::HPUX;
use strict;
use vars qw($runAfter);
$runAfter = ["Ocsinventory::Agent::Backend::OS::Generic"];
sub check { $^O =~ /hpux/ }
sub run {
my $params = shift;
my $common = $params->{common};
my $OSName;
my $OSVersion;
my $OSComment;
#my $uname_path = &_get_path('uname');
# Operating systeminformations
chomp($OSName = `uname -s`);
chomp($OSVersion = `uname -r`);
chomp($OSComment = `uname -l`);
$common->setHardware({
OSNAME => $OSName,
OSCOMMENTS => $OSComment,
OSVERSION => $OSVersion,
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/HPUX/ 0000775 0000000 0000000 00000000000 14323200667 0022441 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/HPUX/Bios.pm 0000664 0000000 0000000 00000002403 14323200667 0023672 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::HPUX::Bios;
use strict;
###
# Version 1.1
# Correction of Bug n 522774
#
# thanks to Marty Riedling for this correction
#
###
sub check { $^O =~ /hpux/ }
sub run {
my $params = shift;
my $common = $params->{common};
my $BiosVersion;
my $BiosDate;
my $SystemModel;
my $SystemSerial;
$SystemModel=`model`;
if ($common->can_run ("machinfo")) {
foreach (`machinfo`) {
if (/Firmware\s+revision\s?[:=]\s+(\S+)/) {
$BiosVersion=$1;
}
if (/achine\s+serial\s+number\s?[:=]\s+(\S+)/) {
$SystemSerial=$1;
}
}
} else {
for (`echo 'sc product cpu;il' | /usr/sbin/cstm | grep "PDC Firmware"`) {
if (/Revision:\s+(\S+)/){
$BiosVersion="PDC $1";
}
}
for (`echo 'sc product system;il' | /usr/sbin/cstm | grep "System Serial Number"`) {
if (/:\s+(\w+)/) {
$SystemSerial=$1;
}
}
}
$common->setBios ({
BVERSION => $BiosVersion,
BDATE => $BiosDate,
BMANUFACTURER => "HP",
SMANUFACTURER => "HP",
SMODEL => $SystemModel,
SSN => $SystemSerial,
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/HPUX/CPU.pm 0000664 0000000 0000000 00000006031 14323200667 0023426 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::HPUX::CPU;
###
# Version 1.1
# Correction of Bug n 522774
#
# thanks to Marty Riedling for this correction
#
###
use strict;
use LWP::UserAgent;
sub check { $^O =~ /hpux/ }
sub run {
my $params = shift;
my $common = $params->{common};
my $processort;
my $processorn;
my $processors="";
my $DeviceType;
my $cpuInfo;
my $serie;
# Using old system HpUX without machinfo
# the Hpux with machinfo will be done after
my %cpuInfos = (
"D200"=>"7100LC 75",
"D210"=>"7100LC 100",
"D220"=>"7300LC 132",
"D230"=>"7300LC 160",
"D250"=>"7200 100",
"D260"=>"7200 120",
"D270"=>"8000 160",
"D280"=>"8000 180",
"D310"=>"7100LC 100",
"D320"=>"7300LC 132",
"D330"=>"7300LC 160",
"D350"=>"7200 100",
"D360"=>"7200 120",
"D370"=>"8000 160",
"D380"=>"8000 180",
"D390"=>"8200 240",
"K360"=>"8000 180",
"K370"=>"8200 200",
"K380"=>"8200 240",
"K400"=>"7200 100",
"K410"=>"7200 120",
"K420"=>"7200 120",
"K460"=>"8000 180",
"K570"=>"8200 200",
"K580"=>"8200 240",
"L1000-36"=>"8500 360",
"L1500-7x"=>"8700 750",
"L3000-7x"=>"8700 750",
"N4000-44"=>"8500 440",
"ia64 hp server rx1620"=>"itanium 1600");
if ( $common->can_run ("machinfo") ) {
foreach ( `machinfo`) {
if ( /Number of CPUs\s+=\s+(\d+)/ ) {
$processorn=$1;
}
if ( /Clock speed\s+=\s+(\d+)\s+MHz/ ) {
$processors=$1;
}
# Added for HPUX 11.31
if ( /Intel\(R\) Itanium 2 9[01]00 series processor \((\d+\.\d+)/ ) {
$processors=$1*1000;
}
if ( /(\d+)\s+logical processors/ ) {
$processorn=$1;
}
# end HPUX 11.31
}
} else {
chomp($DeviceType =`model |cut -f 3- -d/`);
my $cpuInfo = $cpuInfos{"$DeviceType"};
if ( "$cpuInfo" =~ /^(\S+)\s(\S+)/ ) {
$processort=$1;
$processors=$2;
} else {
for ( `echo 'sc product cpu;il' | /usr/sbin/cstm | grep "CPU Module"` ) {
if ( /(\S+)\s+CPU\s+Module/ ) {
$processort=$1;
}
};
for ( `echo 'itick_per_usec/D' | adb -k /stand/vmunix /dev/kmem` ) {
if ( /tick_per_usec:\s+(\d+)/ ) {
$processors=$1;
}
}
};
# NBR CPU
chomp($processorn=`ioscan -Fk -C processor | wc -l`);
#print "HP $processort A $processorn A $processors ";
}
chomp($serie = `uname -m`);
if ( $serie =~ /ia64/) {
$processort="Itanium"
}
if ( $serie =~ /9000/) {
$processort="PA$processort";
}
$common->setHardware({
PROCESSORT => $processort,
PROCESSORN => $processorn,
PROCESSORS => $processors,
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/HPUX/Controller.pm 0000664 0000000 0000000 00000001446 14323200667 0025127 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::HPUX::Controller;
use strict;
sub check { $^O =~ /hpux/ }
sub run {
my $params = shift;
my $common = $params->{common};
my $name;
my $interface;
my $info;
my $type;
my @typeScaned=('ext_bus','fc','psi');
my $scaned;
for (@typeScaned) {
$scaned=$_;
for ( `ioscan -kFC $scaned| cut -d ':' -f 9,11,17,18` ) {
if ( /(\S+):(\S+):(\S+):(.+)/ ) {
$name=$2;
$interface=$3;
$info=$4;
$type=$1;
$common->addController({
'NAME' => $name,
'MANUFACTURER' => "$interface $info",
'TYPE' => $type,
});
};
};
};
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/HPUX/Domains.pm 0000664 0000000 0000000 00000001346 14323200667 0024375 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::HPUX::Domains;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run ("domainname")
}
sub run {
my $params = shift;
my $common = $params->{common};
my $domain;
chomp($domain = `domainname`);
if (!$domain) {
my %domain;
if (open RESOLV, "/etc/resolv.conf") {
while() {
$domain{$2} = 1 if (/^(domain|search)\s+(.+)/);
}
close RESOLV;
}
$domain = join "/", keys %domain;
}
# If no domain name, we send "WORKGROUP"
$domain = 'WORKGROUP' unless $domain;
$common->setHardware({
WORKGROUP => $domain
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/HPUX/Drives.pm 0000664 0000000 0000000 00000002615 14323200667 0024237 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::HPUX::Drives;
sub check { $^O =~ /hpux/ }
sub run {
my $params = shift;
my $common = $params->{common};
my $type;
my $fs;
my $lv;
my $total;
my $free;
for ( `fstyp -l | grep -v nfs` ) {
if ( /^\s*$/ ) { #Blank line
next;
}
$type=$_;
for ( `bdf -t $type `) {
if ( /Filesystem/ ) { ; } ;
if ( /^(\S+)\s(\d+)\s+(\d+)\s+(\d+)\s+(\d+%)\s+(\S+)/ ) {
$lv=$1;
$total=$2;
$free=$3;
$fs=$6;
$common->addDrives({
FREE => $free,
FILESYSTEM => $fs,
TOTAL => $total,
TYPE => $type,
VOLUMN => $lv,
});
};
if ( /^(\S+)\s/) {
$lv=$1;
};
if ( /(\d+)\s+(\d+)\s+(\d+)\s+(\d+%)\s+(\S+)/) {
$total=$1;
$free=$3;
$fs=$5;
# print "fs $fs lv $lv total $total free $free type $type\n";
$common->addDrives({
FREE => $free,
FILESYSTEM => $fs,
TOTAL => $total,
TYPE => $type,
VOLUMN => $lv,
});
};
};
};
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/HPUX/IPv4.pm 0000664 0000000 0000000 00000000744 14323200667 0023566 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::HPUX::IPv4;
sub check {
`which ifconfig 2>&1`; ($? >> 8)?0:1
}
# Initialise the distro entry
sub run {
my $params = shift;
my $common = $params->{common};
my $ip;
my $hostname;
if ( `hostname` =~ /(\S+)/ ) {
$hostname=$1;
}
for ( `grep $hostname /etc/hosts ` ) {
if ( /(^\d+\.\d+\.\d+\.\d+)\s+/ ){
$ip=$1;
$common->setHardware({IPADDR => $ip});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/HPUX/Mem.pm 0000664 0000000 0000000 00000001060 14323200667 0023512 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::HPUX::Mem;
use strict;
sub check { $^O =~ /hpux/ }
sub run {
my $params = shift;
my $common = $params->{common};
my $mem;
my $swap;
$mem = `grep Physical /var/adm/syslog/syslog.log|tr -s " "|cut -f 7 -d " "` ;
if ( $mem eq "" ) {
$mem = `grep Physical /var/adm/syslog/OLDsyslog.log|tr -s " "|cut -f 7 -d " "` ;
};
$mem = int ($mem/1024);
$swap = `swapinfo -mdfq`;
$common->setHardware({
MEMORY => $mem,
SWAP => $swap,
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/HPUX/Memory.pm 0000664 0000000 0000000 00000006352 14323200667 0024255 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::HPUX::Memory;
use strict;
sub check { $^O =~ /hpux/ }
sub run {
my $params = shift;
my $common = $params->{common};
my $capacity=0;
my $caption;
my $description;
my $numslot;
my $subnumslot;
my $serialnumber;
my $type;
my @list_mem=`echo 'sc product mem;il'| /usr/sbin/cstm`;
my $ok=0;
if ( `uname -m` =~ /ia64/ ) {
for ( `echo 'sc product IPF_MEMORY;il' | /usr/sbin/cstm` ) {
if ( /\w+IMM\s+Location/ ) {
;
} elsif ( /(\w+IMM)\s+(\w+)\s+(\S+)\s+(\w+IMM)\s+(\w+)\s+(\S+)/ ) {
$common->addMemories({
CAPACITY => $3,
CAPTION => $2 ,
NUMSLOTS => "1" ,
TYPE => $1,
});
$common->addMemories({
CAPACITY => $6,
CAPTION => $5 ,
NUMSLOTS => "1" ,
TYPE => $4,
});
}
}
} else {
for ( `echo 'sc product system;il' | /usr/sbin/cstm ` ) {
if ( /FRU\sSource\s+=\s+\S+\s+\(memory/ ) {
$ok=0;
#print "FRU Source memory\n";
}
if ( /Source\s+Detail\s+=\s4/ ) {
$ok=1;
#print "Source Detail IMM\n";
}
if ( /Extender\s+Location\s+=\s+(\S+)/ ) {
$subnumslot=$1;
#print "Extended sub $subnumslot\n";
};
if ( /DIMMS\s+Rank\s+=\s+(\S+)/ ) {
$numslot=sprintf("%02x",$1);
#print "Num slot $numslot\n";
}
if ( /FRU\s+Name\.*:\s+(\S+)/ ) {
if ( /(\S+)_(\S+)/ ) {
$type=$1;
$capacity=$2;
#print "Type $type capa $capacity\n";
} elsif ( /(\wIMM)(\S+)/ ) {
$ok=1;
$type=$1;
$numslot=$2;
#print "Type $type numslot $numslot\n";
}
}
if ( /Part\s+Number\.*:\s*(\S+)\s+/ ) {
$description=$1;
#print "ref $description\n";
};
if ( /Serial\s+Number\.*:\s*(\S+)\s+/ ) {
$serialnumber=$1;
if ( $ok eq 1 ) {
if ( $capacity eq 0 ){
foreach ( @list_mem ){
if ( /\s+$numslot\s+(\d+)/ ){
$capacity=$1;
#print "Capacity $capacity\n";
}
}
}
$common->addMemories({
CAPACITY => $capacity,
CAPTION => "Ext $subnumslot Slot $numslot" ,
DESCRIPTION => "Part Number $description",
NUMSLOTS => "1" ,
SERIALNUMBER => $serialnumber,
TYPE => $type,
});
$ok=0;
$capacity=0;
};
#print "Serial $serialnumber\n\n";
};
};
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/HPUX/Networks.pm 0000664 0000000 0000000 00000005106 14323200667 0024615 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::HPUX::Networks;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_load("Net::IP qw(:PROC)");
}
sub run {
my $params = shift;
my $common = $params->{common};
my $name;
my $lanid;
my $ipmask;
my $ipgateway;
my $status;
my $macaddr;
my $speed;
my $type;
my $ipsubnet;
my $description;
my $ipaddress;
my $binip;
my $binmask;
my $binsubnet;
for ( `lanscan -iap`) {
# Reinit variable
$name="";
$lanid="";
$ipmask="";
$ipgateway="";
$status="";
$macaddr="";
$speed="";
$type="";
$ipsubnet="";
$description="";
$ipaddress="";
if ( /^(\S+)\s(\S+)\s(\S+)\s+(\S+)/) {
$name=$2;
$macaddr=$1;
$lanid=$4;
#print "name $name macaddr $macaddr lanid $lanid\n";
for ( `lanadmin -g $lanid` ) {
if (/Type.+=\s(.+)/) { $type = $1; };
if (/Description\s+=\s(.+)/) { $description = $1; };
if (/Speed.+=\s(\d+)/) {
$speed = $1;
unless ( $speed <= 1000000 ) { # in old version speed was given in Mbps
# we want speed in Mbps
$speed = $1/1000000;
}
};
if (/Operation Status.+=\s(.+)/) { $status = $1; };
}; # for lanadmin
#print "name $name macaddr $macaddr lanid $lanid speed $speed status $status \n";
for ( `ifconfig $name 2> /dev/null` ) {
if ( /inet\s(\S+)\snetmask\s(\S+)\s/ ) {
$ipaddress=$1;
$ipmask=$2;
if ($ipmask =~ /(..)(..)(..)(..)/) {
$ipmask=sprintf ("%i.%i.%i.%i",hex($1),hex($2),hex($3),hex($4));
}
};
}; # For ifconfig
$binip = ip_iptobin ($ipaddress ,4);
$binmask = ip_iptobin ($ipmask ,4);
$binsubnet = $binip & $binmask;
$ipsubnet = ip_bintoip($binsubnet,4);
$common->addNetworks({
DESCRIPTION => $description,
IPADDRESS => $ipaddress,
IPGATEWAY => $ipgateway,
IPMASK => $ipmask,
IPSUBNET => $ipsubnet,
MACADDR => $macaddr,
STATUS => $status,
SPEED => $speed,
TYPE => $type,
});
}; # If
}; # For lanscan
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/HPUX/README 0000664 0000000 0000000 00000003067 14323200667 0023327 0 ustar 00root root 0000000 0000000 #####################################################
# 17/12/2009
# Auteur: dwizz.donowin@yahoo.fr
#
# This code is open source and may be copied and modified as long as the source
# code is always made freely available.
# Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
#
################################################################################
Version Francaise
-----------------
(for english version see below)
Ces fichiers sont generes pour etre utilisis avec
l'agent Unix OCS-NG 1.02
Installation:
Installer le client OCS-NG 1.02 avec ces prerequis
extraire les fichiers dans le repertoire
Ocsinventory/Agent/Backend/OS
Ils seront automatiquement pris en compte par le client OCS
Je n'ai pu tester ces fichiers que sur N4000 actuellement en version HP-UX 11.0
J'ai commence sur un rp3440 mais je n'ai pas encore toutes les informations
car le format des certaines donnees change.
N'hesitez pas a m'aider a le faire evoluer.
English version
---------------
This files are producted for using with
the OCS-NG 1.02 Unix Agent
Install:
Install the OCS-NG 1.02 Agent with the prerequesit
Extract the files in the
Ocsinventory/Agent/Backend/OS
It will be used automatically
I have test the script on only n4000 system for th moment on HP-Ux 11.0
I try it on rp3440 but some informations are not in the same format
If you wish to help me, you are welwome.
the files are
HPUX.pm
HPUX sub directory
Bios.pm
CPU.pm
Controller.pm
Domains.pm
Drives.pm
IPv4.pm
Mem.pm
Memory.pm
Networks.pm
Slots.pm
Software.pm
Storages.pm
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/HPUX/Slots.pm 0000664 0000000 0000000 00000001525 14323200667 0024106 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::HPUX::Slots;
use strict;
sub check { $^O =~ /hpux/ }
sub run {
my $params = shift;
my $common = $params->{common};
my $name;
my $interface;
my $info;
my $type;
my @typeScaned=('ioa','ba');
my $scaned;
for (@typeScaned ) {
$scaned=$_;
for ( `ioscan -kFC $scaned| cut -d ':' -f 9,11,17,18` ) {
if ( /(\S+):(\S+):(\S+):(.+)/ ) {
$name=$2;
$interface=$3;
$info=$4;
$type=$1;
$common->addSlots({
DESCRIPTION => "$name",
DESIGNATION => "$interface $info",
NAME => "$type",
STATUS => "OK",
});
};
};
};
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/HPUX/Software.pm 0000664 0000000 0000000 00000001436 14323200667 0024575 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::HPUX::Software;
sub check {
my $params = shift;
# Do not run an package inventory if there is the --nosoftware parameter
return if ($params->{params}->{nosoftware});
$^O =~ /hpux/
}
sub run {
my $params = shift;
my $common = $params->{common};
my @softList;
my $software;
@softList = `swlist | grep -v '^ PH' | grep -v '^#' |tr -s "\t" " "|tr -s " "` ;
foreach $software (@softList) {
chomp( $software );
if ( $software =~ /^ (\S+)\s(\S+)\s(.+)/ ) {
$common->addSoftwares({
'NAME' => $1 ,
'VERSION' => $2 ,
'COMMENTS' => $3 ,
'PUBLISHER' => "HP" ,
});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/HPUX/Storages.pm 0000664 0000000 0000000 00000005451 14323200667 0024573 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::HPUX::Storages;
sub check { $^O =~ /hpux/ }
sub run {
my $params = shift;
my $common = $params->{common};
my @all_type = ("tape","disk") ;
my $type;
my $description;
my $path;
my $vendor;
my $ref;
my $size;
my $devdsk;
my $devrdsk;
my $revlvl;
my $alternate;
for ( @all_type ) {
$type = "$_";
for ( `ioscan -kFnC $type | cut -d ':' -f 1,11,18` ) {
if ( /(\S+)\:(\S+)\:(\S+)\s+(\S+)/ ) {
$description = $1;
$path = $2;
$vendor = $3;
$ref = $4;
};
$alternate = 0 ;
if ( $type eq "disk" ) {
if ( /\s+(\/dev\/dsk\/\S+)\s+(\/dev\/rdsk\/\S+)/ ) {
#print "1 $1 2 $2 \n";
$devdsk=$1;
$devrdsk=$2;
# We look if we are on an alternate link
for ( `pvdisplay $devdsk 2> /dev/null` ) {
if ( /$devdsk\.+lternate/ ) {
$alternate=1;
};
};
# We are not on an alternate link
if ( $alternate eq 0 ) {
#$size = `diskinfo -b $devrdsk`;
for ( `diskinfo -v $devrdsk`) {
if ( /^\s+size:\s+(\S+)/ ) {
$size=$1;
$size = int ( $size/1024 ) if $size;
};
if ( /^\s+rev level:\s+(\S+)/ ) {
$revlvl=$1;
};
};
#print "vendor $vendor ref $ref type $type description $description path $path size $size\n";
$common->addStorages({
MANUFACTURER => $vendor,
MODEL => $ref,
NAME => $devdsk,
DESCRIPTION => $description,
TYPE => $type,
DISKSIZE => $size,
FIRMWARE => $revlvl,
});
};
};
} else {
# We look for tapes
if ( /^\s+(\/dev\/rmt\/\Sm)\s+/ ) {
$devdsk=$1;
$common->addStorages({
MANUFACTURER => $vendor,
MODEL => $ref,
NAME => $devdsk,
DESCRIPTION => $description,
TYPE => $type,
DISKSIZE => ''
});
};
};
};
};
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux.pm 0000664 0000000 0000000 00000001544 14323200667 0023316 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux;
use strict;
use vars qw($runAfter);
$runAfter = ["Ocsinventory::Agent::Backend::OS::Generic"];
sub check { $^O =~ /^linux$/ }
sub run {
my $params = shift;
my $common = $params->{common};
chomp (my $osversion = `uname -r`);
my $lastloggeduser;
my $datelastlog;
my @query = $common->runcmd("last -R -n 1");
foreach ($query[0]) {
if ( s/^(\S+)\s+\S+\s+(\S+\s+\S+\s+\S+\s+\S+)\s+.*// ) {
$lastloggeduser = $1;
$datelastlog = $2;
}
}
# This will probably be overwritten by a Linux::Distro module.
$common->setHardware({
OSNAME => "Linux",
OSCOMMENTS => "Unknown Linux distribution",
OSVERSION => $osversion,
LASTLOGGEDUSER => $lastloggeduser,
DATELASTLOGGEDUSER => $datelastlog
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/ 0000775 0000000 0000000 00000000000 14323200667 0022754 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/ 0000775 0000000 0000000 00000000000 14323200667 0024014 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/ARM.pm 0000664 0000000 0000000 00000000256 14323200667 0024774 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::ARM;
use strict;
use Config;
sub check {
return 1 if $Config{'archname'} =~ /^arm/;
0;
};
sub run{}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/ARM/ 0000775 0000000 0000000 00000000000 14323200667 0024433 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/ARM/Bios.pm 0000664 0000000 0000000 00000003065 14323200667 0025671 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::ARM::Bios;
use strict;
use warnings;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_read("/proc/cpuinfo");
$common->can_run("vcgencmd");
}
sub run {
my $params = shift;
my $common = $params->{common};
my $current;
my @infos;
# processor : 0
# model name : ARMv6-compatible processor rev 7 (v6l)
# BogoMIPS : 697.95
# Features : half thumb fastmult vfp edsp java tls
# CPU implementer : 0x41
# CPU architecture : 7
# CPU variant : 0x0
# CPU part : 0xb76
# CPU revision : 7
#
# Hardware : BCM2835
# Revision : 0002
# Serial : 0000000081355bf5
# Model : Raspberry Pi Model B Rev 1
open INFO, ") {
$current->{SSN} = $1 if /Serial\s+:\s+(\S.*)/;
$current->{BVERSION} = $1 if /Revision\s+:\s+(.*)/;
$current->{TYPE} = $1 if /Model\s+:\s+(.*)/;
push @infos, $current;
}
close(INFO);
# vcgencmd version
my $bd=`vcgencmd version | head -1`;
$bd =~ s/^(#.*\n)//g;
$bd =~ s/Invalid.*$//g;
chomp($bd);
# Writing data
foreach my $info (@infos) {
$info->{ASSETTAG}='N/A';
$info->{SMANUFACTURER}='Raspberry';
$info->{SMODEL}='Raspberry';
$info->{BMANUFACTURER}='N/A';
$info->{BDATE}=$bd;
$info->{MMANUFACTURER}='N/A';
$common->setBios($info);
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/ARM/CPU.pm 0000664 0000000 0000000 00000003020 14323200667 0025413 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::ARM::CPU;
use strict;
use warnings;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("lscpu");
$common->can_run("vcgencmd");
}
sub run {
my $params = shift;
my $common = $params->{common};
my @cpuinfos=`LANG=C lscpu 2>/dev/null`;
my $cpu;
my $nbcpus;
my $freq;
foreach my $info (@cpuinfos){
chomp $info;
$cpu->{CPUARCH}=$1 if ($info =~ /Architecture:\s*(.*)/i);
$cpu->{NBCPUS}=$1 if ($info =~ /^CPU\(s\):\s*(\d+)/i);
$cpu->{THREADS}=$1 if ($info =~ /Thread\(s\)\sper\score:\s*(\d+)/i);
$cpu->{CORES}=$1 if ($info =~ /Core\(s\)\sper\ssocket:\s*(\d+)/i);
$cpu->{NBSOCKET}=$1 if ($info =~ /Socket\(s\):\s*(\d+)/i);
$cpu->{TYPE}=$1 if ($info =~ /Model\sname:\s*(.*)/i);
$cpu->{MANUFACTURER}=$1 if ($info =~ /Vendor ID:\s*(.+)/i);
$cpu->{SPEED}=$1 if ($info =~ /CPU max MHZ:\s*(.*)/i);
if ($cpu->{CPUARCH} && $cpu->{CPUARCH} =~ /(armv[1-7])/){
$cpu->{DATA_WIDTH}='32';
} else {
$cpu->{DATA_WIDTH}='64';
}
}
# Frequency
$cpu->{CURRENT_SPEED}=`vcgencmd get_config arm_freq | cut -d"=" -f 2`;
# Total Threads = number of cores x number of threads per core
$cpu->{THREADS}=$cpu->{CORES}*$cpu->{THREADS};
# Set LOGICAL_CPUS with THREADS value
$cpu->{LOGICAL_CPUS}=$cpu->{THREADS};
for (my $i=0;$i<$cpu->{NBSOCKET};$i++) {
$common->addCPU($cpu);
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/Alpha.pm 0000664 0000000 0000000 00000000262 14323200667 0025377 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::Alpha;
use strict;
use Config;
sub check {
return 1 if $Config{'archname'} =~ /^alpha/;
0;
};
sub run{}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/Alpha/ 0000775 0000000 0000000 00000000000 14323200667 0025041 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/Alpha/CPU.pm 0000664 0000000 0000000 00000001564 14323200667 0026034 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::Alpha::CPU;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_read("/proc/cpuinfo")
}
sub run {
my $params = shift;
my $common = $params->{common};
my @cpu;
my $current;
open CPUINFO, ") {
print;
if (/^cpu\s*:/) {
if ($current) {
$common->addCPU($current);
}
$current = {
CPUARCH => 'Alpha',
};
} else {
$current->{SERIAL} = $1 if /^cpu serial number\s+:\s+(\S.*)/;
$current->{SPEED} = $1 if /cycle frequency \[Hz\]\s+:\s+(\d+)000000/;
$current->{TYPE} = $1 if /platform string\s+:\s+(\S.*)/;
}
}
# The last one
$common->addCPU($current);
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/MIPS.pm 0000664 0000000 0000000 00000000260 14323200667 0025120 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::MIPS;
use strict;
use Config;
sub check {
return 1 if $Config{'archname'} =~ /^mips/;
0;
};
sub run{}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/MIPS/ 0000775 0000000 0000000 00000000000 14323200667 0024564 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/MIPS/CPU.pm 0000664 0000000 0000000 00000001307 14323200667 0025552 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::MIPS::CPU;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_read("/proc/cpuinfo")
}
sub run {
my $params = shift;
my $common = $params->{common};
my @cpu;
my $current;
open CPUINFO, ") {
print;
if (/^system type\s+:\s*:/) {
if ($current) {
$common->addCPU($current);
}
$current = {
CPUARCH => 'MIPS',
};
}
$current->{TYPE} = $1 if /cpu model\s+:\s+(\S.*)/;
}
# The last one
$common->addCPU($current);
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/PowerPC.pm 0000664 0000000 0000000 00000000274 14323200667 0025674 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::PowerPC;
use strict;
use Config;
sub check {
return 1 if $Config{'archname'} =~ /^(ppc|powerpc)/;
0;
};
sub run{}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/PowerPC/ 0000775 0000000 0000000 00000000000 14323200667 0025333 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/PowerPC/CPU.pm 0000664 0000000 0000000 00000002447 14323200667 0026327 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::PowerPC::CPU;
use strict;
#processor : 0
#cpu : POWER4+ (gq)
#clock : 1452.000000MHz
#revision : 2.1
#
#processor : 1
#cpu : POWER4+ (gq)
#clock : 1452.000000MHz
#revision : 2.1
#
#timebase : 181495202
#machine : CHRP IBM,7029-6C3
#
#
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_read ("/proc/cpuinfo")
}
sub run {
my $params = shift;
my $common = $params->{common};
my @cpus;
my $current;
my $isIBM;
open CPUINFO, ") {
$isIBM = 1 if /^machine\s*:.*IBM/;
$current->{TYPE} = $1 if /cpu\s+:\s+(\S.*)/;
$current->{SPEED} = $1 if /clock\s+:\s+(\S.*)/;
$current->{SPEED} =~ s/\.[0-9]+MHz//;
if (/^\s*$/) {
if ($current->{TYPE}) {
push @cpus, $current;
}
$current = {};
}
}
if (/^\s*$/) {
if ($current->{TYPE}) {
push @cpus, $current;
}
$current = {};
}
foreach my $cpu (@cpus) {
$cpu->{MANUFACTURER} = 'IBM' if $isIBM;
$cpu->{CPUARCH} = 'PowerPC';
$common->addCPU($cpu);
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/PowerPC/Various.pm 0000664 0000000 0000000 00000003174 14323200667 0027326 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::PowerPC::Various;
use strict;
sub check { 1 };
sub run {
my $params = shift;
my $common = $params->{common};
############ Motherboard
my $SystemManufacturer;
my $SystemModel;
my $SystemSerial;
my $BiosManufacturer;
my $BiosVersion;
my $BiosDate;
if (open SERIAL,";
$SystemSerial =~ s/[^\,^\.^\w^\ ]//g; # I remove some unprintable char
close SERIAL;
}
if (open MODEL,";
$SystemModel =~ s/[^\,^\.^\w^\ ]//g;
close MODEL;
}
if (open COLOR,";
close COLOR;
my ($color) = unpack "h7" , $tmp;
$SystemModel = $SystemModel." color: $color" if $color;
}
if (open OPENBOOT,";
$BiosVersion =~ s/[^\,^\.^\w^\ ]//g;
close OPENBOOT;
}
if (open COPYRIGHT,";
close COPYRIGHT;
if ($tmp =~ /Apple/) {
# What about the Apple clone?
$BiosManufacturer = "Apple Computer, Inc.";
$SystemManufacturer = "Apple Computer, Inc."
}
}
$common->setBios ({
SMANUFACTURER => $SystemManufacturer,
SMODEL => $SystemModel,
SSN => $SystemSerial,
BMANUFACTURER => $BiosManufacturer,
BVERSION => $BiosVersion,
BDATE => $BiosDate,
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/SPARC.pm 0000664 0000000 0000000 00000000262 14323200667 0025222 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::SPARC;
use strict;
use Config;
sub check {
return 1 if $Config{'archname'} =~ /^sparc/;
0;
};
sub run{}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/SPARC/ 0000775 0000000 0000000 00000000000 14323200667 0024664 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/SPARC/CPU.pm 0000664 0000000 0000000 00000001121 14323200667 0025644 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::SPARC::CPU;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_read ("/proc/cpuinfo")
}
sub run {
my $params = shift;
my $common = $params->{common};
my @cpu;
my $current = { CPUARCH => 'ARM' };
my $ncpus = 1;
open CPUINFO, ") {
$current->{TYPE} = $1 if /cpu\s+:\s+(\S.*)/;
$ncpus = $1 if /ncpus probed\s+:\s+(\d+)/
}
foreach (1..$ncpus) {
$common->addCPU($current);
}
}
1
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/i386.pm 0000664 0000000 0000000 00000000270 14323200667 0025042 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::i386;
use strict;
use Config;
sub check {
return 1 if $Config{'archname'} =~ /^(i\d86|x86_64)/;
0;
};
sub run{}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/i386/ 0000775 0000000 0000000 00000000000 14323200667 0024505 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/i386/CPU.pm 0000664 0000000 0000000 00000004547 14323200667 0025504 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::i386::CPU;
use strict;
use warnings;
use Data::Dumper;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("lscpu");
}
sub run {
my $params = shift;
my $common = $params->{common};
my @cpuinfos=`LANG=C lscpu`;
my $cpu;
my $nbcpus;
foreach my $info (@cpuinfos){
chomp $info;
$cpu->{CPUARCH}=$1 if ($info =~ /Architecture:\s*(.*)/i);
$cpu->{NBCPUS}=$1 if ($info =~ /^CPU\(s\):\s*(\d+)/i);
$cpu->{THREADS}=$1 if ($info =~ /Thread\(s\)\sper\score:\s*(\d+)/i);
$cpu->{CORES}=$1 if ($info =~ /Core\(s\)\sper\ssocket:\s*(\d+)/i);
$cpu->{NBSOCKET}=$1 if ($info =~ /Socket\(s\):\s*(\d+)/i);
$cpu->{TYPE}=$1 if ($info =~ /Model\sname:\s*(.*)/i);
if ($info =~ /Vendor ID:\s*(Authentic|Genuine|)(.+)/i){
$cpu->{MANUFACTURER} = $2;
$cpu->{MANUFACTURER} =~ s/(TMx86|TransmetaCPU)/Transmeta/;
$cpu->{MANUFACTURER} =~ s/CyrixInstead/Cyrix/;
$cpu->{MANUFACTURER} =~ s/CentaurHauls/VIA/;
}
$cpu->{CURRENT_SPEED} = $1 if ($info =~ /CPU\sMHz:\s*(\d+)(|\.\d+)$/i);
$cpu->{L2CACHESIZE} = $1 if ($info =~ /L2\scache:\s*(.*)/i);
if ($cpu->{CPUARCH} && $cpu->{CPUARCH} eq 'x86_64'){
$cpu->{DATA_WIDTH}='64';
} else {
$cpu->{DATA_WIDTH}='32';
}
if ($cpu->{TYPE}) {
if ($cpu->{TYPE} =~ /([\d\.]+)MHz$/){
$cpu->{SPEED}=$1;
} elsif ($cpu->{TYPE} =~ /([\d\.]+)GHz$/){
$cpu->{SPEED}=$1*1000;
}
}
}
# Total Threads = number of cores x number of threads per core
$cpu->{THREADS}=$cpu->{CORES}*$cpu->{THREADS};
# Set LOGICAL_CPUS with THREADS value
$cpu->{LOGICAL_CPUS}=$cpu->{THREADS};
# set CURRENT_ADDRESS_WIDTH with DATA_WIDTH value
$cpu->{CURRENT_ADDRESS_WIDTH}=$cpu->{DATA_WIDTH};
my $infos=$common->getDmidecodeInfos();
foreach my $info (@{$infos->{4}}) {
next if $info->{Status} && $info->{Status} =~ /Unpopulated|Disabled/i;
$cpu->{SERIALNUMBER}=$info->{'Serial Number'};
$cpu->{VOLTAGE}=$info->{'Voltage'};
$cpu->{SOCKET}=$info->{'Socket Designation'};
}
for (my $i=0;$i<$cpu->{NBSOCKET};$i++) {
$common->addCPU($cpu);
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/m68k.pm 0000664 0000000 0000000 00000000256 14323200667 0025142 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::m68k;
use strict;
use Config;
sub check {
return 1 if $Config{'archname'} =~ /^m68k/;
0;
};
sub run{}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/m68k/ 0000775 0000000 0000000 00000000000 14323200667 0024601 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/m68k/CPU.pm 0000664 0000000 0000000 00000001412 14323200667 0025564 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::m68k::CPU;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_read("/proc/cpuinfo")
}
sub run {
my $params = shift;
my $common = $params->{common};
my @cpu;
my $current;
open CPUINFO, ") {
print;
if (/^CPU\s+:\s*:/) {
if ($current) {
$common->addCPU($current);
}
$current = {
CPUARCH => 'm68k',
};
} else {
$current->{TYPE} = $1 if /CPU:\s+(\S.*)/;
$current->{SPEED} = $1 if /Clocking:\s+:\s+(\S.*)/;
}
}
# The last one
$common->addCPU($current);
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/s390x.pm 0000664 0000000 0000000 00000000261 14323200667 0025237 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::s390x;
use strict;
use Config;
sub check {
return 1 if $Config{'archname'} =~ /^s390/;
0;
};
sub run{}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/s390x/ 0000775 0000000 0000000 00000000000 14323200667 0024702 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Archs/s390x/CPU.pm 0000664 0000000 0000000 00000001435 14323200667 0025672 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Archs::s390x::CPU;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_read("/proc/cpuinfo")
}
sub run {
my $params = shift;
my $common = $params->{common};
my $current;
my $cpucores;
open CPUINFO, ") {
print;
if (/^vendor\s*:/) {
if ($current) {
$common->addCPU($current);
}
} elsif (/^processor [0-9]:\s+(\S.*)/) {
$cpucores++;
}
$current->{MANUFACTURER} = $1 if /vendor_id\s*:\s+(\S.*)/;
$current->{SPEED} = $1 if /bogomips per cpu:\s+(\S.*)/;
}
$current->{CORES} = $cpucores;
$common->addCPU($current);
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Bios.pm 0000664 0000000 0000000 00000005101 14323200667 0024203 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Bios;
use vars qw($runMeIfTheseChecksFailed);
$runMeIfTheseChecksFailed = ["Ocsinventory::Agent::Backend::OS::Generic::Dmidecode::Bios"];
use strict;
use warnings;
sub check {
return -d "/sys/class/dmi/id";
}
sub run {
my $params = shift;
my $common = $params->{common};
my $chassis_types = [
"",
"Other",
"Unknown",
"Desktop",
"Low Profile Desktop",
"Pizza Box",
"Mini Tower",
"Tower",
"Portable",
"Laptop",
"Notebook",
"Hand Held",
"Docking Station",
"All in One",
"Sub Notebook",
"Space-Saving",
"Lunch Box",
"Main Server Chassis",
"Expansion Chassis",
"Sub Chassis",
"Bus Expansion Chassis",
"Peripheral CHassis",
"RAID Chassis",
"Rack Mount Chassis",
"Sealed-case PC",
"Multi-System",
"CompactPCI",
"AdvancedTCA",
"Blade",
"Blade Enclosing",
"Tablet",
"Convertible",
"Detachable",
"IoT Gateway",
"Embedded PC",
"Mini PC",
"Stick PC",
];
my $bios = {};
my $hardware = {};
my %bios_map = qw(
BMANUFACTURER bios_vendor
BDATE bios_date
BVERSION bios_version
ASSETTAG chassis_asset_tag
SMODEL product_name
SMANUFATCURER sys_vendor
SSN product_serial
MMODEL board_name
MMANUFACTURER board_vendor
MSN board_serial
);
foreach my $key (keys(%bios_map)){
my $value = _dmi_info($bios_map{$key});
next unless defined($value);
$bios->{$key}=$value;
}
# Set VirtualBox VM S/N to UUID if found serial is '0'
my $uuid = _dmi_info('product_uuid');
if ($uuid && $bios->{MMODEL} && $bios->{MMODEL} eq 'VirtualBox' && $bios->{SSN} eq "0" && $bios->{MSN} eq "0" ){
$bios->{SSN}=$uuid;
}
$hardware->{UUID}=$uuid if $uuid;
my $chassis_type = _dmi_info('chassis_type');
if ($chassis_type && $chassis_types->[$chassis_type]) {
$bios->{TYPE} = $chassis_types->[$chassis_type];
}
$common->setBios($bios);
$common->setHardware($hardware);
}
1;
sub _dmi_info {
my ($info) = @_;
my $class = '/sys/class/dmi/id/'.$info;
return if -d $class;
return unless -e $class;
open (my $fh, $class) or warn;
my $classinfo=<$fh>;
close ($fh);
chomp($classinfo);
return $classinfo;
}
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/ 0000775 0000000 0000000 00000000000 14323200667 0024220 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/LSB.pm 0000664 0000000 0000000 00000001330 14323200667 0025173 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::LSB;
use vars qw($runMeIfTheseChecksFailed);
$runMeIfTheseChecksFailed = ["Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB"];
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("lsb_release")
}
sub run {
my $params = shift;
my $common = $params->{common};
my $OSname;
chomp($OSname =`lsb_release -is`);
my $OSversion;
chomp($OSversion =`lsb_release -rs`);
my $OSComment;
chomp($OSComment =`uname -v`);
my $release = "$OSname $OSVersion";
$common->setHardware({
OSNAME => $release,
OSVERSION => $OSversion,
OSCOMMENTS => "$OSComment"
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB.pm 0000664 0000000 0000000 00000000242 14323200667 0025647 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB;
$runMeIfTheseChecksFailed = ["Ocsinventory::Agent::Backend::OS::Linux::Distro::OSRelease"];
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB/ 0000775 0000000 0000000 00000000000 14323200667 0025313 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB/ArchLinux.pm 0000664 0000000 0000000 00000000765 14323200667 0027556 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB::ArchLinux;
use strict;
sub check {-f "/etc/arch-release"}
#####
sub findRelease {
my $v;
open V, ");
close V;
return "ArchLinux $v";
}
sub run {
my $params = shift;
my $common = $params->{common};
my $OSComment;
chomp($OSComment =`uname -v`);
$common->setHardware({
OSNAME => findRelease(),
OSCOMMENTS => "$OSComment"
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB/CentOS.pm 0000664 0000000 0000000 00000001102 14323200667 0026776 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB::CentOS;
use strict;
sub check {
-f "/etc/centos-release"
&&
!readlink ("/etc/centos-release")
&&
!-f "/etc/vmware-release"
}
####
sub findRelease {
my $v;
open V, ");
close V;
$v;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $OSComment;
chomp($OSComment =`uname -v`);
$common->setHardware({
OSNAME => findRelease(),
OSCOMMENTS => "$OSComment"
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB/Debian.pm 0000664 0000000 0000000 00000001041 14323200667 0027027 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB::Debian;
use strict;
sub check {-f "/etc/debian_version" && !-f "/etc/ubuntu_version"}
#####
sub findRelease {
my $v;
open V, ");
close V;
return "Debian GNU/Linux $v";
}
sub run {
my $params = shift;
my $common = $params->{common};
my $OSComment;
chomp($OSComment =`uname -v`);
$common->setHardware({
OSNAME => findRelease(),
OSCOMMENTS => "$OSComment"
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB/Fedora.pm 0000664 0000000 0000000 00000000752 14323200667 0027055 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB::Fedora;
use strict;
sub check {-f "/etc/fedora-release"}
#####
sub findRelease {
my $v;
open V, ");
close V;
$v;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $OSComment;
chomp($OSComment =`uname -v`);
$common->setHardware({
OSNAME => findRelease(),
OSCOMMENTS => "$OSComment"
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB/Gentoo.pm 0000664 0000000 0000000 00000001000 14323200667 0027073 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB::Gentoo;
use strict;
sub check {-f "/etc/gentoo-release"}
#####
sub findRelease {
my $v;
open V, ");
close V;
return "Gentoo Linux $v";
}
sub run {
my $params = shift;
my $common = $params->{common};
my $OSComment;
chomp($OSComment =`uname -v`);
$common->setHardware({
OSNAME => findRelease(),
OSCOMMENTS => "$OSComment"
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB/Knoppix.pm 0000664 0000000 0000000 00000001033 14323200667 0027276 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB::Knoppix;
use strict;
sub check {-f "/etc/knoppix_version"}
#####
sub findRelease {
my $v;
open V, ");
close V;
print $v."\n";
return "Knoppix GNU/Linux $v";
}
sub run {
my $params = shift;
my $common = $params->{common};
my $OSComment;
chomp($OSComment =`uname -v`);
$common->setHardware({
OSNAME => findRelease(),
OSCOMMENTS => "$OSComment"
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB/Mandrake.pm 0000664 0000000 0000000 00000001013 14323200667 0027366 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB::Mandrake;
use strict;
sub check {-f "/etc/mandrake-release" && !-f "/etc/mandriva-release"}
#####
sub findRelease {
my $v;
open V, ");
close V;
$v;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $OSComment;
chomp($OSComment =`uname -v`);
$common->setHardware({
OSNAME => findRelease(),
OSCOMMENTS => "$OSComment"
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB/Mandriva.pm 0000664 0000000 0000000 00000001043 14323200667 0027410 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB::Mandriva;
use strict;
sub check {-f "/etc/mandrake-release" && -f "/etc/mandriva-release"}
#####
sub findRelease {
my $v;
open V, ");
close V;
return $v if $v;
0;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $OSComment;
chomp($OSComment =`uname -v`);
$common->setHardware({
OSNAME => findRelease(),
OSCOMMENTS => "$OSComment"
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB/Oracle.pm 0000664 0000000 0000000 00000000773 14323200667 0027065 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB::Oracle;
use strict;
sub check {-f "/etc/oracle-release"}
#####
sub findRelease {
my $v;
open V, ");
close V;
return $v if $v;
0;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $OSComment;
chomp($OSComment =`uname -v`);
$common->setHardware({
OSNAME => findRelease(),
OSCOMMENTS => "$OSComment"
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB/Redhat.pm 0000664 0000000 0000000 00000001104 14323200667 0027054 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB::Redhat;
use strict;
sub check {
-f "/etc/redhat-release"
&&
!readlink ("/etc/redhat-release")
&&
!-f "/etc/vmware-release"
}
####
sub findRelease {
my $v;
open V, ");
close V;
$v;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $OSComment;
chomp($OSComment =`uname -v`);
$common->setHardware({
OSNAME => findRelease(),
OSCOMMENTS => "$OSComment"
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB/Slackware.pm 0000664 0000000 0000000 00000001141 14323200667 0027562 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB::Slackware;
use strict;
sub check {-f "/etc/slackware-version"}
#####
sub findRelease {
my $v;
open V, ");
foreach (){
$v=$1 if (/Slackware ([\d.]+)/);
close V;
return $v;
}
}
sub run {
my $params = shift;
my $common = $params->{common};
my $OSComment;
chomp($OSComment =`uname -v`);
$common->setHardware({
OSNAME => "Slackware",
OSVERSION => findRelease(),
OSCOMMENTS => "$OSComment"
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB/SuSE.pm 0000664 0000000 0000000 00000001315 14323200667 0026470 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB::SuSE;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_read ("/etc/SuSE-release")
}
sub run {
my $v;
my $version;
my $patchlevel;
my $params = shift;
my $common = $params->{common};
open V, ") {
next if (/^#/);
$version=$1 if (/^VERSION = ([0-9]+)/);
$patchlevel=$1 if (/^PATCHLEVEL = ([0-9]+)/);
}
close V;
$common->setHardware({
OSNAME => "SUSE Linux Enterprise Server $version SP$patchlevel",
OSVERSION => $version,
OSCOMMENTS => $patchlevel
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB/Trustix.pm 0000664 0000000 0000000 00000000755 14323200667 0027342 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB::Trustix;
use strict;
sub check {-f "/etc/trustix-release"}
#####
sub findRelease {
my $v;
open V, ");
close V;
$v;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $OSComment;
chomp($OSComment =`uname -v`);
$common->setHardware({
OSNAME => findRelease(),
OSCOMMENTS => "$OSComment"
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB/Ubuntu.pm 0000664 0000000 0000000 00000001144 14323200667 0027133 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB::Ubuntu;
use strict;
use vars qw($runAfter);
$runAfter = ["Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB::Debian"];
sub check {-f "/etc/ubuntu_version"}
#####
sub findRelease {
my $v;
open V, ");
close V;
return "Ubuntu $v";
}
sub run {
my $params = shift;
my $common = $params->{common};
my $OSComment;
chomp($OSComment =`uname -v`);
$common->setHardware({
OSNAME => findRelease(),
OSCOMMENTS => "$OSComment"
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/NonLSB/VmWare.pm 0000664 0000000 0000000 00000000752 14323200667 0027056 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::NonLSB::VmWare;
use strict;
sub check { -f "/etc/vmware-release" }
####
sub findRelease {
my $v;
open V, ");
close V;
$v;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $OSComment;
chomp($OSComment =`uname -v`);
$common->setHardware({
OSNAME => findRelease(),
OSCOMMENTS => "$OSComment"
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Distro/OSRelease.pm 0000664 0000000 0000000 00000002624 14323200667 0026404 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Distro::OSRelease;
use warnings;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_read ("/etc/os-release")
}
sub run {
my $name;
my $version;
my $description;
my $params = shift;
my $common = $params->{common};
open V, "/etc/os-release" or warn;
foreach () {
next if /^#/;
$name = $1 if (/^NAME="?([^"]+)"?/);
$version = $1 if (/^VERSION_ID="?([^"]+)"?/);
$description=$1 if (/^PRETTY_NAME="?([^"]+)"?/);
}
close V;
chomp($name);
# Debian version number is set in/etc/debian_version file
if (-r "/etc/debian_version") {
if (`uname -v` =~ /debian/i) {
open V, "/etc/debian_version" or warn;
foreach () {
$version = $1 if ($_ =~ /^(\d+.*)/);
}
close V;
chomp($version);
}
}
# CentOS exact version number is set in /etc/centos-release file
if (-r "/etc/centos-release") {
open V, "/etc/centos-release" or warn;
foreach ($description=) {
$version = $1 if ($_ =~ /(\d+\.\d+)./g);
}
close V;
chomp($version);
chomp($description);
}
$common->setHardware({
OSNAME => "$name $version",
OSVERSION => $version,
OSCOMMENTS => $description,
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Domains.pm 0000664 0000000 0000000 00000001777 14323200667 0024720 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Domains;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run ("hostname");
my @domain = `hostname -d`;
return 1 if @domain || $common->can_read ("/etc/resolv.conf");
0;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $domain;
my %domain;
my @dns_list;
my $dns;
chomp($domain = `hostname -d`);
open RESOLV, "/etc/resolv.conf" or warn;
while (){
if (/^nameserver\s+(\S+)/i) {
push(@dns_list,$1);
} elsif (!$domain) {
$domain{$2} = 1 if (/^(domain|search)\s+(.+)/);
}
}
close RESOLV;
if (!$domain) {
$domain = join "/", keys %domain;
}
$dns=join("/",@dns_list);
# If no domain name, we send "WORKGROUP"
$domain = 'WORKGROUP' unless $domain;
$common->setHardware({
WORKGROUP => $domain,
DNS => $dns
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Drives.pm 0000664 0000000 0000000 00000011661 14323200667 0024553 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Drives;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run ("df");
my $df = `df -TP`;
return 1 if $df =~ /\w+/;
0
}
sub run {
my $params = shift;
my $common = $params->{common};
my %months = (
Jan => 1,
Fev => 2,
Mar => 3,
Apr => 4,
May => 5,
Jun => 6,
Jul => 7,
Aug => 8,
Sep => 9,
Oct => 10,
Nov => 11,
Dec => 12,
);
my %listVolume = ();
# Get complementary information in hash tab
if ($common->can_run ("lshal")) {
my %temp;
my $in = 0;
my $value;
foreach my $line (`lshal`) {
chomp $line;
if ( $line =~ s{^udi = '/org/freedesktop/Hal/devices/volume.*}{}) {
$in = 1;
%temp = ();
} elsif ($in == 1 and $line =~ s{^\s+(\S+) = (.*) \s*\((int|string|bool|string list|uint64)\)}{} ) {
if ($3 ne 'int' and $3 ne 'uint64') {
chomp($value = $2);
if ($3 eq 'string') {
chop($value);
#$value =~ s/^'?(.*)'?$/$1/g;
$value=substr($value,1,length($value));
$value=substr($value,0,length($value)-1);
}
$temp{$1} = $value;
} else {
$temp{$1} = (split(/\W/,$2))[0];
}
} elsif ($in== 1 and $line eq '') {
$in = 0 ;
$listVolume{$temp{'block.device'}} = {%temp};
}
}
}
foreach(`df -TP`) { # TODO retrieve error
my $createdate;
my $free;
my $filesystem;
my $label;
my $total;
my $type;
my $volumn;
my $serial;
if (/^(\S+)\s+(\S+)\s+(\S+)\s+(?:\S+)\s+(\S+)\s+(?:\S+)\s+(\S+)\n/){
$free = sprintf("%i",($4/1024));
$filesystem = $2;
$total = sprintf("%i",($3/1024));
$type = $5;
$volumn = $1;
# no virtual FS
next if ($filesystem =~ /^(tmpfs|devtmpfs|usbfs|proc|devpts|devshm|udev)$/);
next if ($type =~ /^(tmpfs|devtmpfs)$/);
if ($filesystem =~ /^ext(2|3|4|4dev)/ && $common->can_run('dumpe2fs')) {
foreach (`dumpe2fs -h $volumn 2> /dev/null`) {
if (/Filesystem UUID:\s+(\S+)/) {
$serial = $1;
} elsif (/Filesystem created:\s+\w+ (\w+) (\d+) ([\d:]+) (\d{4})$/) {
$createdate = $4.'/'.$months{$1}.'/'.$2.' '.$3;
} elsif (/Filesystem volume name:\s*(\S.*)/) {
$label = $1 unless $1 eq '';
}
}
} elsif ($filesystem =~ /^xfs$/ && $common->can_run('xfs_db')) {
foreach (`xfs_db -r -c uuid $volumn`) {
$serial = $1 if /^UUID =\s+(\S+)/;
;
}
foreach (`xfs_db -r -c label $volumn`) {
$label = $1 if /^label =\s+"(\S+)"/;
}
} elsif ($filesystem =~ /^vfat$/ && $common->can_run('dosfslabel')) {
chomp ($label = `dosfslabel $volumn`);
}
$label =~ s/\s+$//;
$serial =~ s/\s+$//;
# Check information and improve it
if (keys %listVolume) {
if ( defined $listVolume{$volumn} ) {
if ($filesystem eq '') { $filesystem = $listVolume{$volumn}->{'volume.fstype'};}
if ($label eq '') { $label = $listVolume{$volumn}->{'volume.label'};}
if ($total eq '') { $total = int($listVolume{$volumn}->{'volume.size'}/(1024*1024) + 0.5);}
if ($type eq '') { $type = $listVolume{$volumn}->{'storage.model'};}
if ($serial eq '') { $serial = $listVolume{$volumn}->{'volume.uuid'};}
delete ($listVolume{$volumn});
}
}
$common->addDrive({
CREATEDATE => $createdate,
FREE => $free,
FILESYSTEM => $filesystem,
LABEL => $label,
TOTAL => $total,
TYPE => $type,
VOLUMN => $volumn,
SERIAL => $serial
});
}
}
if ($common->can_run ("lshal")) {
while (my ($k,$v) = each %listVolume ) {
$common->addDrive({
FILESYSTEM => $v->{'volume.fstype'},
LABEL => $v->{'volume.label'},
TOTAL => int ($v->{'volume.size'}/(1024*1024) + 0.5),
TYPE => $v->{'storage.model'},
VOLUMN => $k,
SERIAL => $v->{'volume.uuid'}
});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Inputs.pm 0000664 0000000 0000000 00000002645 14323200667 0024603 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Inputs;
use strict;
use warnings;
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my $in;
my $vendor;
my $phys;
my $name;
my $type;
if (open INPUTS, ") {
if (/^I: Bus=.*Vendor=(.*) Prod/){
$in=1;
$vendor=$1;
} elsif ($_ =~ /^$/) {
$in=0;
if ($phys && $phys =~ "input"){
$common->addInput({
DESCRIPTION=>$name,
CAPTION=>$name,
TYPE=>$type
});
}
} elsif ($in) {
if (/^P: Phys=.*(button).*/i) {
$phys="nodev";
} elsif (/^P: Phys=.*(input).*/i) {
$phys="input";
}
if (/^N: Name=\"(.*)\"/i){
$name=$1;
}
if (/^H: Handlers=(\w+)/i) {
if ($1 =~ ".*kbd.*") {
$type="Keyboard";
} elsif ($1 =~ ".*mouse.*") {
$type="Pointing";
} else {
$type=$1;
}
}
}
}
close INPUTS;
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/LVM.pm 0000664 0000000 0000000 00000004262 14323200667 0023754 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::LVM;
use strict;
use vars qw($runAfter);
$runAfter = ["Ocsinventory::Agent::Backend::OS::Linux::Drives"];
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run ("pvs");
1
}
sub run {
my $params = shift;
my $common = $params->{common};
use constant MB => (1024*1024);
if ($common->can_run('pvs')) {
foreach (`pvs --noheading --nosuffix --units b -o +pv_uuid`) {
chomp;
$_ =~s/^\s+//;
my @vs_elem=split('\s+');
my $status='VG: '.$vs_elem[1].', Fmt: '.$vs_elem[2].', Attr: '.$vs_elem[3];
$common->addDrive({
FREE => $vs_elem[5]/MB,
FILESYSTEM => 'LVM PV',
TOTAL => $vs_elem[4]/MB,
TYPE => $vs_elem[0],
VOLUMN => $status,
SERIAL => $vs_elem[6]
});
}
}
if ($common->can_run('vgs')) {
foreach (`vgs --noheading --nosuffix --units b -o +vg_uuid,vg_extent_size`) {
chomp;
$_ =~s/^\s+//;
my @vs_elem=split('\s+');
my $status = 'PV/LV: '.$vs_elem[1].'/'.$vs_elem[2]
.', Attr: '.$vs_elem[4].', PE: '.($vs_elem[8]/MB).' MB';
$common->addDrive({
FREE => $vs_elem[6]/MB,
FILESYSTEM => 'LVM VG',
TOTAL => $vs_elem[5]/MB,
TYPE => $vs_elem[0],
VOLUMN => $status,
SERIAL => $vs_elem[7]
});
}
}
if ($common->can_run('lvs')) {
foreach (`lvs -a --noheading --nosuffix --units b -o lv_name,vg_name,lv_attr,lv_size,lv_uuid,seg_count`) {
chomp;
$_ =~s/^\s+//;
my @vs_elem=split('\s+');
my $status='Attr: '.$vs_elem[2].', Seg: '.$vs_elem[5];
$common->addDrive({
FREE => 0,
FILESYSTEM => 'LVM LV',
TOTAL => $vs_elem[3]/MB,
TYPE => $vs_elem[1].'/'.$vs_elem[0],
VOLUMN => $status,
SERIAL => $vs_elem[4]
});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Mem.pm 0000664 0000000 0000000 00000001256 14323200667 0024034 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Mem;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_read ("/proc/meminfo")
}
sub run {
my $params = shift;
my $common = $params->{common};
my $unit = 1024;
my $PhysicalMemory;
my $SwapFileSize;
# Memory informations
open MEMINFO, "/proc/meminfo";
while(){
$PhysicalMemory=$1 if /^memtotal\s*:\s*(\S+)/i;
$SwapFileSize=$1 if /^swaptotal\s*:\s*(\S+)/i;
}
# TODO
$common->setHardware({
MEMORY => sprintf("%i",$PhysicalMemory/$unit),
SWAP => sprintf("%i", $SwapFileSize/$unit),
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Network/ 0000775 0000000 0000000 00000000000 14323200667 0024405 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Network/IP.pm 0000664 0000000 0000000 00000002243 14323200667 0025254 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Network::IP;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run ("ip") || $common->can_run("ifconfig");
1;
}
# Initialise the distro entry
sub run {
my $params = shift;
my $common = $params->{common};
my @ip;
my @ip6;
if ($common->can_run("ip")){
foreach (`ip a`){
if (/inet (\S+)\/\d{1,2}/){
($1=~/^127.+/)?next:push @ip,$1;
} elsif (/inet6 (\S+)\d{2}/){
($1=~/::1\/128/)?next:push @ip6, $1;
}
}
} elsif ($common->can_run("ifconfig")){
foreach (`ifconfig`){
#if(/^\s*inet\s*(\S+)\s*netmask/){
if (/^\s*inet add?r\s*:\s*(\S+)/ || /^\s*inet\s+(\S+)/){
($1=~/^127.+/)?next:push @ip, $1;
} elsif (/^\s*inet6\s+(\S+)/){
($1=~/::1/)?next:push @ip6, $1;
}
}
}
my $ip=join "/", @ip;
my $ip6=join "/", @ip6;
if (defined $ip) {
$common->setHardware({IPADDR => $ip});
} else {
$common->setHardware({IPADDR => $ip6});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Network/Networks.pm 0000664 0000000 0000000 00000104221 14323200667 0026557 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Network::Networks;
use strict;
use warnings;
use Data::Dumper;
use File::stat;
use Time::Local;
sub check {
my $params = shift;
my $common = $params->{common};
if ($common->can_run("ip") && $common->can_load("Net::IP qw(:PROC)") || ($common->can_run("ifconfig") && $common->can_run("route")) && $common->can_load("Net::IP qw(:PROC)")){
return 1;
} else {
return 0;
}
}
sub getLeaseFile {
my $if = @_;
my @directories = qw(
/var/db
/var/lib/dhclient
/var/lib/dhcp3
/var/lib/dhcp
/var/lib/NetworkManager
);
my @patterns = ("*$if*.lease", "*.lease*", "dhclient.leases.$if");
my @files;
foreach my $directory (@directories) {
next unless -d $directory;
foreach my $pattern (@patterns) {
push @files,
grep { -s $_ }
glob("$directory/$pattern");
}
}
return unless @files;
@files =
map {$_->[0]}
sort {$a->[1]->ctime()<=>$b->[1]->ctime()}
map {[$_,stat($_)]}
@files;
return $files[-1];
}
sub _ipdhcp {
my $if = shift;
my $path;
my $dhcp;
my $ipdhcp;
my $leasepath;
$leasepath = getLeaseFile($if);
if ( $leasepath and $leasepath =~ /internal/ ) {
if (open DHCP, $leasepath) {
while() {
if (/SERVER_ADDRESS=(\d{1,3}(?:\.\d{1,3}){3})/) {
$ipdhcp=$1;
}
}
close DHCP or warn;
} else {
warn ("Can't open $leasepath\n");
}
} elsif( $leasepath ) {
if (open DHCP, $leasepath) {
my $lease;
while(){
$lease = 1 if(/lease\s*{/i);
$lease = 0 if(/^\s*}\s*$/);
#Interface name
if ($lease) { #inside a lease section
if (/interface\s+"(.+?)"\s*/){
$dhcp = ($1 =~ /^$if$/);
}
#Server IP
if (/option\s+dhcp-server-identifier\s+(\d{1,3}(?:\.\d{1,3}){3})\s*;/ and $dhcp){
$ipdhcp = $1;
}
}
}
close DHCP or warn;
} else {
warn "Can't open $leasepath\n";
}
}
return $ipdhcp;
}
# Initialise the distro entry
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my $description;
my $driver;
my @ipaddress;
my $ipaddress;
my $ipgateway;
my $ipmask;
my $ipsubnet;
my $ipaddress6;
my $ipgateway6;
my $ipmask6;
my $ipsubnet6;
my $macaddr;
my $pcislot;
my $status;
my $type;
my $virtualdev;
my $settings;
my $speed;
my $current_speed;
my $duplex;
my $ssid;
my $bssid;
my $mode;
my $version;
my $bitrate;
my $mtu;
my @netsum;
my $basedev;
my $slave;
my %gateway;
my @secondary;
my $ipsecond;
if ($common->can_run("ip")){
my @netsum = `ip addr show`;
push @netsum, "\n";
chomp @netsum;
for (my $i=0;$i<=$#netsum;$i+=1) {
my $line=$netsum[$i];
if ($line =~ /^(\d+(?) {
$driver = $1 if /^DRIVER=(\S+)/;
$pcislot = $1 if /^PCI_SLOT_NAME=(\S+)/;
}
close UEVENT;
}
if (-d "/sys/class/net/$description/wireless"){
my @wifistatus = `iwconfig $description 2>/dev/null`;
foreach my $line (@wifistatus){
$ssid = $1 if ($line =~ /ESSID:(\S+)/);
$version = $1 if ($line =~ /IEEE (\S+)/);
$mode = $1 if ($line =~ /Mode:(\S+)/);
$bssid = $1 if ($line =~ /Access Point: (\S+)/);
$bitrate = $1 if ($line =~ /Bit\sRate=\s*(\S+\sMb\/s)/i);
}
$type = "Wifi";
$status=1;
} elsif (-f "/sys/class/net/$description/mode") {
$type="infiniband";
} else {
$type="ethernet";
}
if (defined ($ipgateway)) {
$common->setHardware({
DEFAULTGATEWAY => $ipgateway
});
} elsif (defined ($ipgateway6)){
$common->setHardware({
DEFAULTGATEWAY => $ipgateway6
});
}
# Retrieve speed from /sys/class/net/$description/speed
$speed=getSpeed($description);
# Retrieve duplex from /sys/class/net/$description/duplex
$duplex=getDuplex($description);
# Retrieve mtu from /sys/class/net/$description/mtu
$mtu=getMTU($description);
# Retrieve status from /sys/class/net/$description/status
$status=getStatus($description);
if ($description && $ip) {
if ($type eq "Wifi") {
$common->addNetwork({
DESCRIPTION => $description,
DRIVER => $driver,
IPADDRESS => $ip,
IPDHCP => _ipdhcp($description),
IPGATEWAY => $ipgateway,
IPMASK => $ipmask,
IPSUBNET => $ipsubnet,
MACADDR => $macaddr,
PCISLOT => $pcislot,
STATUS => $status?"Up":"Down",
TYPE => $type,
SPEED => $bitrate,
SSID => $ssid,
BSSID => $bssid,
IEEE => $version,
MODE => $mode,
MTU => $mtu,
});
} else {
$common->addNetwork({
DESCRIPTION => $description,
DRIVER => $driver,
IPADDRESS => $ip,
IPDHCP => _ipdhcp($description),
IPGATEWAY => $ipgateway,
IPMASK => $ipmask,
IPSUBNET => $ipsubnet,
MACADDR => $macaddr,
PCISLOT => $pcislot,
STATUS => $status?"Up":"Down",
TYPE => $type,
VIRTUALDEV => $virtualdev,
DUPLEX => $duplex?"Full":"Half",
SPEED => $speed,
MTU => $mtu,
});
}
}
if ($description && $ipaddress6) {
if ($type eq "Wifi") {
$common->addNetwork({
DESCRIPTION => $description,
DRIVER => $driver,
IPADDRESS => $ipaddress6,
IPDHCP => undef,
IPGATEWAY => $ipgateway6,
IPMASK => $ipmask6,
IPSUBNET => $ipsubnet6,
MACADDR => $macaddr,
PCISLOT => $pcislot,
STATUS => $status?"Up":"Down",
TYPE => $type,
SPEED => $bitrate,
SSID => $ssid,
BSSID => $bssid,
IEEE => $version,
MODE => $mode,
MTU => $mtu,
});
} else {
$common->addNetwork({
DESCRIPTION => $description,
DRIVER => $driver,
IPADDRESS => $ipaddress6,
IPGATEWAY => $ipgateway6,
IPDHCP => undef,
IPMASK => $ipmask6,
IPSUBNET => $ipsubnet6,
MACADDR => $macaddr,
PCISLOT => $pcislot,
STATUS => $status?"Up":"Down",
TYPE => $type,
DUPLEX => $duplex?"Full":"Half",
SPEED => $speed,
MTU => $mtu,
VIRTUALDEV => $virtualdev,
});
}
}
if ($description && !$ip && !$ipaddress6) {
if ($type eq "Wifi") {
$common->addNetwork({
DESCRIPTION => $description,
DRIVER => $driver,
MACADDR => $macaddr,
PCISLOT => $pcislot,
STATUS => $status?"Up":"Down",
TYPE => $type,
SPEED => $bitrate,
SSID => $ssid,
BSSID => $bssid,
IEEE => $version,
MODE => $mode,
MTU => $mtu,
});
} else {
$common->addNetwork({
DESCRIPTION => $description,
DRIVER => $driver,
MACADDR => $macaddr,
PCISLOT => $pcislot,
STATUS => $status?"Up":"Down",
TYPE => $type,
VIRTUALDEV => $virtualdev,
DUPLEX => $duplex?"Full":"Half",
SPEED => $speed,
MTU => $mtu,
});
}
}
# Virtual devices
# Reliable way to get the info
if (-d "/sys/devices/virtual/net/") {
$virtualdev = (-d "/sys/devices/virtual/net/$description")?"1":"0";
} elsif ($common->can_run("brctl")) {
# Let's guess
my %bridge;
foreach (`brctl show`) {
next if /^bridge name/;
$bridge{$1} = 1 if /^(\w+)\s/;
}
if ($pcislot) {
$virtualdev = "1";
} elsif ($bridge{$description}) {
$virtualdev = "0";
}
$type = "bridge";
$common->addNetwork({
DESCRIPTION => $description,
TYPE => $type,
VIRTUALDEV => $virtualdev,
});
}
# Check if this is dialup interface
if ($description =~ m/^ppp$/) {
$type="dialup";
$virtualdev=1;
$common->addNetwork({
DESCRIPTION => $description,
TYPE => $type,
VIRTUALDEV => $virtualdev,
});
}
# Check if this is a bonding slave
if (-d "/sys/class/net/$description/bonding"){
$slave=getslaves($description);
$type="aggregate";
$virtualdev=1;
$common->addNetwork({
SLAVE => $slave,
TYPE => $type,
VIRTUALDEV => $virtualdev,
});
}
# Check if this is an alias or tagged interface
if ($description =~ m/^([\w\d]+)[:.]\d+$/) {
$basedev=$1;
$type="alias";
$virtualdev=1;
$common->addNetwork({
BASE => $basedev,
DESCRIPTION => $description,
TYPE => $type,
VIRTUALDEV => $virtualdev,
});
}
# Check if this is a vlan
if (-f "/proc/net/vlan/$description"){
$type="vlan";
$virtualdev=1;
$common->addNetwork({
BASE => $basedev,
DESCRIPTION => $description,
TYPE => $type,
VIRTUALDEV => $virtualdev,
});
}
$ipaddress6 = $ipgateway6 = $ipmask6 = $ipsubnet6 = undef;
}
# Retrieve speed from /sys/class/net/$description/speed
$speed=getSpeed($description);
# Retrieve duplex from /sys/class/net/$description/duplex
$duplex=getDuplex($description);
# Retrieve mtu from /sys/class/net/$description/mtu
$mtu=getMTU($description);
if ($description && $ipaddress6) {
if ($type eq "Wifi") {
$common->addNetwork({
DESCRIPTION => $description,
DRIVER => $driver,
IPADDRESS => $ipaddress6,
IPDHCP => undef,
IPGATEWAY => $ipgateway6,
IPMASK => $ipmask6,
IPSUBNET => $ipsubnet6,
MACADDR => $macaddr,
PCISLOT => $pcislot,
STATUS => $status?"Up":"Down",
TYPE => $type,
SPEED => $bitrate,
SSID => $ssid,
BSSID => $bssid,
IEEE => $version,
MODE => $mode,
MTU => $mtu,
});
} else {
$common->addNetwork({
DESCRIPTION => $description,
DRIVER => $driver,
IPADDRESS => $ipaddress6,
IPGATEWAY => $ipgateway6,
IPDHCP => undef,
IPMASK => $ipmask6,
IPSUBNET => $ipsubnet6,
MACADDR => $macaddr,
PCISLOT => $pcislot,
STATUS => $status?"Up":"Down",
TYPE => $type,
DUPLEX => $duplex?"Full":"Half",
SPEED => $speed,
MTU => $mtu,
VIRTUALDEV => $virtualdev,
});
}
}
if ($description && !$ipaddress && !$ipaddress6) {
if ($type eq "Wifi") {
$common->addNetwork({
DESCRIPTION => $description,
DRIVER => $driver,
MACADDR => $macaddr,
PCISLOT => $pcislot,
STATUS => $status?"Up":"Down",
TYPE => $type,
SPEED => $bitrate,
SSID => $ssid,
BSSID => $bssid,
IEEE => $version,
MODE => $mode,
MTU => $mtu,
});
} else {
$common->addNetwork({
DESCRIPTION => $description,
DRIVER => $driver,
MACADDR => $macaddr,
PCISLOT => $pcislot,
STATUS => $status?"Up":"Down",
TYPE => $type,
VIRTUALDEV => $virtualdev,
DUPLEX => $duplex?"Full":"Half",
SPEED => $speed,
MTU => $mtu,
});
}
}
# Check if this is a secondary ip address
if (@secondary) {
foreach my $info (@secondary) {
$ipsecond=$1 if ($info =~ /inet ((?:\d{1,3}+\.){3}\d{1,3})\/(\d+)/);
$basedev=$description;
$type="secondary";
$virtualdev=1;
$common->addNetwork({
BASE => $basedev?$basedev : undef,
DESCRIPTION => $description,
IPADDRESS => $ipsecond,
IPGATEWAY => $ipgateway,
IPMASK => $ipmask,
IPSUBNET => $ipsubnet,
MACADDR => $macaddr,
TYPE => $type,
VIRTUALDEV => $virtualdev?"Virtual":"Physical",
});
}
}
$description = $driver = $ipaddress = $ipgateway = $ipmask = $ipsubnet = $ipaddress6 = $ipgateway6 = $ipmask6 = $ipsubnet6 = $macaddr = $pcislot = $status = $type = $virtualdev = $speed = $duplex = $mtu = undef;
@secondary=();
@ipaddress=();
}
$description = $1 if ($line =~ /^\d+:\s+([^:@]+)/); # Interface name
if ($description && $description eq "lo" ) { next; } # loopback interface is not inventoried
if ($line =~ /inet ((?:\d{1,3}+\.){3}\d{1,3})\/(\d+)/i && $line !~ /secondary/i){
push @ipaddress, $1;
$ipaddress=$1;
$ipmask=getIPNetmask($2);
$ipsubnet=getSubnetAddressIPv4($ipaddress,$ipmask);
$ipgateway=getIPRoute($ipaddress,$ipmask);
} elsif ($line =~ /\s+link\/(\S+)/){
$type=$1;
$macaddr=getMAC($description);
} elsif ($line =~ /inet6 (\S+)\/(\d{1,2})/i){
$ipaddress6=$1;
$ipmask6=getIPNetmaskV6($2);
$ipsubnet6=getSubnetAddressIPv6($ipaddress6,$ipmask6);
$ipgateway6=getIPRoute($ipaddress6,$ipmask6);
}
# Retrieve secondary ip addresses if defined
if ($line =~ /secondary/i){
push @secondary, $line;
}
}
} elsif ($common->can_run("ifconfig")){
foreach my $line (`ifconfig -a`) {
if ($line =~ /^$/ && $description && $macaddr) {
# end of interface section
# I write the entry
if (defined($ipgateway)){
$common->setHardware({
DEFAULTGATEWAY => $ipgateway
});
} elsif (defined($ipgateway6)) {
$common->setHardware({
DEFAULTGATEWAY => $ipgateway6
});
}
if (-d "/sys/class/net/$description/wireless"){
my @wifistatus = `iwconfig $description`;
foreach my $line (@wifistatus){
$ssid = $1 if ($line =~ /ESSID:(\S+)/);
$version = $1 if ($line =~ /IEEE (\S+)/);
$mode = $1 if ($line =~ /Mode:(\S+)/);
$bssid = $1 if ($line =~ /Access Point: (\S+)/);
$bitrate = $1 if ($line =~ /Bit\sRate=\s*(\S+\sMb\/s)/i);
}
$type = "Wifi";
} elsif (-f "/sys/class/net/$description/mode") {
$type="infiniband";
}
if (open UEVENT, ") {
$driver = $1 if /^DRIVER=(\S+)/;
$pcislot = $1 if /^PCI_SLOT_NAME=(\S+)/;
}
close UEVENT;
}
# Retrieve speed from /sys/class/net/$description/speed
$speed=getSpeed($description);
# Retrieve duplex from /sys/class/net/$description/duplex
$duplex=getDuplex($description);
# Virtual devices
# Reliable way to get the info
if (-d "/sys/devices/virtual/net/") {
$virtualdev = (-d "/sys/devices/virtual/net/$description")?"1":"0";
} elsif ($common->can_run("brctl")) {
# Let's guess
my %bridge;
foreach (`brctl show`) {
next if /^bridge name/;
$bridge{$1} = 1 if /^(\w+)\s/;
}
if ($pcislot) {
$virtualdev = "1";
} elsif ($bridge{$description}) {
$virtualdev = "0";
}
$type = "bridge";
}
# Check if this is dialup interface
if ($description =~ m/^ppp$/) {
$type="dialup";
$virtualdev=1;
}
# Check if this is an alias or tagged interface
if ($description =~ m/^([\w\d]+)[:.]\d+$/) {
$basedev=$1;
$type="alias";
$virtualdev=1;
}
# Check if this is a bonding slave
if (-d "/sys/class/net/$description/bonding"){
$slave=getslaves($description);
$type="aggregate";
$virtualdev=1;
}
# Check if this is a vlan
if (-f "/proc/net/vlan/$description"){
$type="vlan";
$virtualdev=1;
}
if ($description && $ipaddress) {
if ($type eq "Wifi") {
$common->addNetwork({
DESCRIPTION => $description,
DRIVER => $driver,
IPADDRESS => $ipaddress,
IPDHCP => _ipdhcp($description),
IPGATEWAY => $ipgateway,
IPMASK => $ipmask,
IPSUBNET => $ipsubnet,
MACADDR => $macaddr,
PCISLOT => $pcislot,
STATUS => $status?"Up":"Down",
TYPE => $type,
SPEED => $bitrate,
SSID => $ssid,
BSSID => $bssid,
IEEE => $version,
MODE => $mode,
});
} else {
$common->addNetwork({
BASE => $basedev?$basedev : undef,
DESCRIPTION => $description,
DRIVER => $driver,
IPADDRESS => $ipaddress,
IPDHCP => _ipdhcp($description),
IPGATEWAY => $ipgateway,
IPMASK => $ipmask,
IPSUBNET => $ipsubnet,
MACADDR => $macaddr,
PCISLOT => $pcislot,
STATUS => $status?"Up":"Down",
TYPE => $type,
VIRTUALDEV => $virtualdev,
DUPLEX => $duplex?"Full":"Half",
SPEED => $speed,
MTU => $mtu,
SLAVE => $slave?$slave : undef,
});
}
} elsif ($description && $ipaddress6) {
$common->addNetwork({
BASE => $basedev?$basedev : undef,
DESCRIPTION => $description,
DRIVER => $driver,
IPADDRESS => $ipaddress6,
IPDHCP => _ipdhcp($description),
IPGATEWAY => $ipgateway6,
IPMASK => $ipmask6,
IPSUBNET => $ipsubnet6,
MACADDR => $macaddr,
PCISLOT => $pcislot,
STATUS => $status?"Up":"Down",
TYPE => $type,
VIRTUALDEV => $virtualdev,
DUPLEX => $duplex?"Full":"Half",
SPEED => $speed,
MTU => $mtu,
SLAVE => $slave?$slave : undef,
});
}
}
if ($line =~ /^$/) { # End of section
$description = $driver = $ipaddress = $ipgateway = $ipmask = $ipsubnet = $macaddr = $pcislot = $status = $type = $virtualdev = $speed = $duplex = $mtu = undef;
} else { # In a section
if ($line =~ /^(\S+):/) {
$description = $1; # Interface name
if ($description && $description eq "lo" ) { next; } # loopback interface is not inventoried
}
if ($line =~ /inet add?r:(\S+)/i || $line =~ /^\s*inet\s+(\S+)/i || $line =~ /inet (\S+)\s+netmask/i){
$ipaddress=$1;
$ipmask=getIPNetmask($ipaddress);
$ipsubnet=getSubnetAddressIPv4($ipaddress,$ipmask);
$ipgateway=getRouteIfconfig($ipaddress,$ipmask);
} elsif ($line =~ /inet6 (\S+)\s+prefixlen\s+(\d{2})/i){
$ipaddress6=$1;
$ipmask6=getIPNetmaskV6($ipaddress6);
$ipsubnet6=getSubnetAddressIPv6($ipaddress6,$ipmask6);
$ipgateway6=getRouteIfconfig($ipaddress6,$ipmask6);
}
$macaddr = $1 if ($line =~ /hwadd?r\s+(\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2})/i || $line =~ /ether\s+(\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2})/i);
$status = 1 if ($line =~ /^\s+UP\s/ || $line =~ /flags=.*[<,]UP[,>]/);
$type = $1 if ($line =~ /link encap:(\S+)/i);
$type = $2 if ($line =~ /^\s+(loop|ether).*\((\S+)\)/i);
if ($type eq "ether" || $type eq "Ethernet") {
$type="ethernet";
}
# Retrieve mtu from /sys/class/net/$description/mtu
$mtu=getMTU($description);
}
}
}
}
sub getslaves{
my ($name)=@_;
my @slaves= map{$_ =~/\/lowr_(\w+)$/} glob("/sys/class/net/$name/lower_*");
return join(",", @slaves);
}
sub getSpeed{
my ($prefix)=@_;
my $speed;
my $current_speed=0;
return undef unless $prefix;
if ( ! -z "/sys/class/net/$prefix/speed") {
open SPEED, "){
$current_speed=$_;
}
close SPEED;
chomp($current_speed);
if ($current_speed eq "65535" || $current_speed eq ""){
$current_speed = "Unknown";
}
if ($current_speed gt 100 ){
$speed = ($current_speed/1000)." Gbps";
} else {
$speed = $current_speed." Mbps";
}
}
return $speed;
}
sub getDuplex{
my ($prefix)=@_;
my $duplex;
return undef unless $prefix;
if (open DUPLEX, "){
$duplex=chomp($_);
}
close DUPLEX;
}
return $duplex;
}
sub getMTU {
my ($prefix)=@_;
my $mtu;
return undef unless $prefix;
if (open MTU, "){
chomp;
$mtu=$_;
}
close MTU;
}
return $mtu;
}
sub getStatus {
my ($prefix)=@_;
my $status;
return undef unless $prefix;
if (open STATUS, "){
chomp;
$status=$_;
}
close STATUS;
}
return $status;
}
sub getMAC {
my ($prefix)=@_;
my $mac;
return undef unless $prefix;
if (open MAC, "){
chomp;
$mac=$_;
}
close MAC;
}
return $mac;
}
sub getSubnetAddressIPv4 {
my ($address,$mask)=@_;
return undef unless $address && $mask;
my $binaddress=ip_iptobin($address, 4);
my $binmask=ip_iptobin($mask, 4);
my $binsubnet=$binaddress & $binmask;
return ip_bintoip($binsubnet, 4);
}
sub getIPNetmask {
my ($prefix) = @_;
return undef unless $prefix;
return ip_bintoip(ip_get_mask($prefix, 4), 4);
}
sub getSubnetAddressIPv6 {
my ($address,$mask)=@_;
return undef unless $address && $mask;
my $binaddress = ip_iptobin(ip_expand_address($address, 6),6);
my $binmask = ip_iptobin(ip_expand_address($mask, 6),6);
my $binsubnet = $binaddress & $binmask;
return ip_compress_address(ip_bintoip($binsubnet, 6),6);
}
sub getIPNetmaskV6 {
my ($prefix) = @_;
return undef unless $prefix;
return ip_compress_address(ip_bintoip(ip_get_mask($prefix, 6), 6),6);
}
sub getIPRoute {
my ($prefix,$net) = @_;
my $gateway;
my $route;
return undef unless $prefix;
if (ip_is_ipv4($prefix)) {
foreach my $line (`ip route`){
if ($line =~ /^default via ((?:\d{1,3}+\.){3}\d{1,3}) /){
$gateway=$1;
};
$route = $gateway if isSameNetwork($prefix,$gateway,$net);
}
} elsif (ip_is_ipv6($prefix)) {
foreach my $line (`ip -6 route`){
next if $line =~ /^Unreachable/;
$route = $1 if $line =~ /^(.*)\/.*/;
}
}
return $route;
}
sub getRouteIfconfig {
my ($prefix) = @_;
my $route;
return undef unless $prefix;
if (ip_is_ipv4($prefix)) {
foreach my $line (`route -n`){
next if $line =~ /^Default/;
$route = $1 if $line =~ /^0.0.0.0\s+(\S+)/;
}
} elsif (ip_is_ipv6($prefix)) {
foreach my $line (`route -6n`){
next if $line =~ /^2002/;
$route = $1 if $line =~ /^(.*)\/.*/;
}
}
return $route;
}
sub isSameNetwork {
my ($address1, $address2, $mask) = @_;
## no critic (ExplicitReturnUndef)
return undef unless $address1 && $address2 && $mask;
my $binaddress1 = ip_iptobin($address1, 4);
my $binaddress2 = ip_iptobin($address2, 4);
my $binmask = ip_iptobin($mask, 4);
## no critic (ProhibitBitwise)
return ($binaddress1 & $binmask) eq ($binaddress2 & $binmask);
}
sub isSameNetworkIPv6 {
my ($address1, $address2, $mask) = @_;
## no critic (ExplicitReturnUndef)
return undef unless $address1 && $address2 && $mask;
my $binaddress1 = ip_iptobin(ip_expand_address($address1, 6), 6);
my $binaddress2 = ip_iptobin(ip_expand_address($address2, 6), 6);
my $binmask = ip_iptobin(ip_expand_address($mask, 6), 6);
## no critic (ProhibitBitwise)
return ($binaddress1 & $binmask) eq ($binaddress2 & $binmask);
}
1;
__END__
__END__
=head1 NAME
OCSInventory::Agent::Backend::OS::Linux::Network::Networks - Network-related functions
=head1 DESCRIPTION
This module retrieves network information.
=head1 FUNCTIONS
=head2 getSpeed
Returns the speed of the card.
=head2 getDuplex
Returns duplex state of the card.
=head2 getMTU
Returns the mtu of the card.
=head2 getStatus
Returns the status of the card.
=head2 getMAC
Returns the mac address.
=head2 getSubnetAddress($address, $mask)
Returns the subnet address for IPv4.
=head2 getSubnetAddressIPv6($address, $mask)
Returns the subnet address for IPv6.
=head2 getIPNetmask($prefix)
Returns the network mask for IPv4.
=head2 getIPNetmaskV6($prefix)
Returns the network mask for IPv6.
=head2 getslaves
Returns if card has a bonding.
=head2 getIPRoute
Returns the gateway defined int he ip config.
=head2 getRouteIfconfig
Returns the gateway defined in the ip config.
=head2 isSameNetwork
Returns true if both addresses belong to the same network, for IPv4.
=head2 isSameNetworkIPv6
Returns true if both addresses belong to the same network, for IPv6.
=back
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Storages.pm 0000664 0000000 0000000 00000053217 14323200667 0025111 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Storages;
use strict;
use XML::Simple;
sub check {
my $params = shift;
my $common = $params->{common};
return unless ($common->can_run("lshw") || $common->can_run("lsscsi") || $common->can_run("lsblk") || $common->can_run("smartctl") || $common->can_run("multipath") || $common->can_run("udevinfo") || $common->can_run("udevadm") || $common->can_run("hdparm"));
}
######## TODO
# Do not remove, used by other modules
sub getFromUdev {
my @devs;
foreach (glob ("/dev/.udev/db/*")) {
my ($scsi_coid, $scsi_chid, $scsi_unid, $scsi_lun, $path, $device, $vendor, $model, $revision, $serial, $serial_short, $type, $bus, $capacity);
if (/^(\/dev\/.udev\/db\/.*)([sh]d[a-z]+)$/) {
$path = $1;
$device = $2;
open (PATH, $1 . $2);
while () {
if (/^S:.*-scsi-(\d+):(\d+):(\d+):(\d+)/) {
$scsi_coid = $1;
$scsi_chid = $2;
$scsi_unid = $3;
$scsi_lun = $4;
}
$vendor = $1 if /^E:ID_VENDOR=(.*)/;
$model = $1 if /^E:ID_MODEL=(.*)/;
$revision = $1 if /^E:ID_REVISION=(.*)/;
$serial = $1 if /^E:ID_SERIAL=(.*)/;
$serial_short = $1 if /^E:ID_SERIAL_SHORT=(.*)/;
$type = $1 if /^E:ID_TYPE=(.*)/;
$bus = $1 if /^E:ID_BUS=(.*)/;
}
$serial_short = $serial unless $serial_short =~ /\S/;
$capacity = getCapacity($device);
push (@devs, {NAME => $device, MANUFACTURER => $vendor, MODEL => $model, DESCRIPTION => $bus, TYPE => $type, DISKSIZE => $capacity, SERIALNUMBER => $serial_short, FIRMWARE => $revision, SCSI_COID => $scsi_coid, SCSI_CHID => $scsi_chid, SCSI_UNID => $scsi_unid, SCSI_LUN => $scsi_lun});
close (PATH);
}
}
return @devs;
}
sub getFromSysProc {
my($dev, $file) = @_;
my $value;
foreach ("/sys/block/$dev/device/$file", "/proc/ide/$dev/$file") {
next unless open PATH, $_;
chomp(my $value = );
$value =~ s/^(\w+)\W*/$1/;
return $value;
}
}
sub getCapacity {
my ($dev) = @_;
my $cap;
chomp ($cap = `fdisk -s /dev/$dev 2>/dev/null`); #requires permissions on /dev/$dev
$cap = int ($cap*1024) if $cap;
return $cap;
}
sub getDescription {
my ($name, $manufacturer, $description, $serialnumber) = @_;
# detected as USB by udev
# TODO maybe we should trust udev detection by default?
return "USB" if (defined ($description) && $description =~ /usb/i);
if ($name =~ /^sd/) { # /dev/sd* are SCSI _OR_ SATA
if ($manufacturer =~ /ATA/ || $serialnumber =~ /ATA/ || $description =~ /ATA/i) {
return "SATA";
} else {
return "SCSI";
}
} elsif ($name =~ /^sg/) { # "g" stands for Generic SCSI
return "SCSI";
} elsif ($name =~ /^vd/ || ($description && $description =~ /VIRTIO/)) {
return "Virtual";
} else {
return $description || "IDE";
}
}
sub getManufacturer {
my ($model) = @_;
#if($model =~ /(maxtor|western|sony|compaq|hewlett packard|ibm|seagate|toshiba|fujitsu|lg|samsung|nec|transcend)/i) {
# return ucfirst(lc($1));
if ($model =~ /^(IBM|LG|NEC$)/){
return $1;
} elsif ($model =~ /(maxtor|western|sony|compaq|hewlett packard|ibm|seagate|toshiba|fujitsu|lg|samsung|nec$|transcend)/i) {
$model = lc($1);
$model = s/\b(\w)/\u$1/g;
return $model;
} elsif ($model =~ /^HP/) {
return "Hewlett-Packard";
} elsif ($model =~ /^WD/) {
return "Western Digital";
} elsif ($model =~ /^ST/) {
return "Seagate";
} elsif ($model =~ /^(HD|IC|HU)/) {
return "Hitachi";
} elsif ($model =~ /^NECVMWar/) {
return "VMware";
} elsif ($model =~ /^VBOX/){
return "Virtual Box";
} else {
return $model;
}
}
sub getMultipathDisks {
my @mpList = `multipath -l`;
my @devs;
my $volume;
my $serial;
my $dm;
my $manufacturer;
my $model;
foreach my $line (@mpList) {
if ($line =~ /^([\w\d]+)\s\((.*)\)\s(dm-\d+)\s(\w+)\s+,([\w\d\s]+)$/i) {
$volume = $1;
$serial = $2;
$dm = $3;
$manufacturer = $4;
$model = $5;
}
if ($line =~ /size=(\d+)(\w+)\s/) {
my $size = $1;
my $unit = $2;
# conversion to mebibyte
my %conversion = (
"T" => 1000**4,
"G" => 1000**3,
"M" => 1000**2,
"K" => 1000,
);
if ($conversion{$unit}) {
$size = $size / $conversion{$unit} * 2**20;
} else {
$size = $size." ".$unit;
}
push (@devs, {NAME=>$dm, DESCRIPTION=>$volume, TYPE=>"Multipath volume", MODEL=>$model, SERIALNUMBER=>$serial, MANUFACTURER=>$manufacturer});
}
if ($line =~ /(sd[a-z]+)/i) {
push (@devs, {NAME=>$1, DESCRIPTION=>"Child of $dm", TYPE=>"Multipath child"});
}
}
return @devs;
}
# some hdparm release generated kernel error if they are
# run on CDROM device
# http://forums.ocsinventory-ng.org/viewtopic.php?pid=20810
sub correctHdparmAvailable {
my $hdparmVersion = `hdparm -V`;
if ($hdparmVersion =~ /^hdparm v(\d+)\.(\d+)(\.|$)/) {
return 1 if $1>9;
return 1 if $1==9 && $2>=15;
}
return;
}
# get available md softraid devices
sub getMdDevices {
return unless ( open(my $fh, '<:encoding(UTF-8)', '/proc/mdstat') );
my @lines = <$fh>;
close($fh);
my $devName;
my $raidLevel;
my @devs;
foreach (@lines) {
chomp($_);
if (/^(md\d*)\s*:\s*\w*\s*(raid\d)/) {
$devName = $1;
$raidLevel = $2;
push (@devs, {NAME => $devName, MODEL => $raidLevel});
}
}
return @devs;
}
# get available block devices from /dev
sub getFromDev {
my @devs;
my @disks;
my $dir = "/dev";
opendir (my $dh, $dir) or die $!;
@disks = grep{/^sd[a-z][a-z]?$|^sg[a-z][a-z]?$|^vd[a-z][a-z]?$|^sr\d+$/} readdir($dh);
foreach (@disks) {
push (@devs, {NAME => $_});
}
return @devs;
}
# get data from lshw
sub getFromLshw {
my @devs;
my @inputlines = `lshw -class disk -xml -quiet`;
return unless $inputlines[0] =~ /xml/i;
my $foundcdroms = 0;
my $input;
foreach (@inputlines) {
if ( /\/g) { # adding "" root element because
$input =~ s/\?>/\?>\n/; # prior to version B.02.16, "lshw -class disk -xml" produces xml output
$input .= "\n
"; # without the "" root element, which does not parse correctly.
}
my $xml = new XML::Simple;
my $data = $xml->XMLin($input);
my $list = $data->{list}->{node};
my $nodes;
# if there is only device, its hash is returned
if ( exists $list->{id} ) {
$nodes->{$list->{id}} = $list;
} else {
$nodes = $list;
}
foreach my $device (sort keys %$nodes) {
my $description = "";
my $size = 0;
my $sizeUnits = "";
my $name = "not set";
my $type = "";
my $vendor = "";
my $model = "";
my $serial = "";
my $revision = "";
if ($nodes->{$device}->{description}) {
$description = $nodes->{$device}->{description};
}
if ($nodes->{$device}->{size}) {
my %units = ('bytes', 1, 'kilobytes', 10**3, 'megabytes', 10**6, 'gigabytes', 10**9, 'terabytes', 10**12);
$sizeUnits = $nodes->{$device}->{size}->{units};
$size = $nodes->{$device}->{size}->{content};
$size = $size * $units{$sizeUnits};
$size = sprintf "%i", $size;
}
if ($nodes->{$device}->{logicalname}) {
$name = $nodes->{$device}->{logicalname};
if (ref($name) eq 'ARRAY') {
foreach (@{$name}) {
if (!readlink $_) {
$name = $_;
last;
}
}
}
$name =~ s/\/dev\///;
}
if ($nodes->{$device}->{type}) {
$type = $nodes->{$device}->{type};
}
if ($nodes->{$device}->{vendor}) {
$vendor = $nodes->{$device}->{vendor};
}
if ($nodes->{$device}->{model}) {
$model = $nodes->{$device}->{model};
}
if ($nodes->{$device}->{serial}) {
$serial = $nodes->{$device}->{serial};
}
push (@devs, {
NAME => $name,
MANUFACTURER => getManufacturer($vendor),
MODEL => $model,
DESCRIPTION => $description,
TYPE => $type,
DISKSIZE => $size,
SERIALNUMBER => $serial,
FIRMWARE => $revision
});
}
return @devs;
}
# get data from lsscsi
sub getFromLsscsi {
my @devs;
my ($id, $type, $vendor, $model, $rev, $device);
foreach my $line (`lsscsi`) {
($id, $type, $vendor, $model, $rev, $device) = unpack ('a13a8a9a17a6a15', $line);
$vendor =~ s/\s*$//;
$type =~ s/\s*$//;
$model =~ s/\s*$//;
my @columns = split /\s+/, $line;
my $deviceName = $columns[-1];
$deviceName =~ s/\/dev\///;
#debug print Dumper {NAME => $deviceName, MANUFACTURER => $vendor, TYPE => $type, MODEL => $model};
if ($type =~ /cd\/dvd|disk/) {
push (@devs, {NAME => $deviceName, MANUFACTURER => getManufacturer($vendor), TYPE => $type, MODEL => $model});
}
}
return @devs;
}
# get data from lsblk
sub getFromLsblk {
my @devs;
foreach my $line (`lsblk -ldbn`) {
my @columns = split /\s+/, $line;
my $deviceName = $columns[0];
my $size = $columns[3];
my $type = $columns[5];
$size = "" if ($type =~ /rom/);
push (@devs, {NAME => $deviceName, TYPE => $type, DISKSIZE => $size});
}
return @devs;
}
# get data from smartctl
sub getFromSmartctl {
my ($params, $devices) = @_;
my @devs;
foreach my $device (keys %$devices) {
my $vendor = "";
my $product = "";
my $revision = "";
my $size = "";
my $type = "";
my $serialnum = "";
my $description = "";
my $devName = $devices->{$device}->{NAME};
foreach my $line (`smartctl -i /dev/$devName`) {
chomp($line);
if ($line =~ m/Model Family:\s+(\S+.*)\s*$/i){
$vendor = $1;
} elsif ($line =~ m/Vendor:\s+(\S+.*)\s*$/i) {
$vendor = $1;
} elsif ($line =~ m/Device Model:\s+(\S+.*)\s*$/i){
$product = $1;
} elsif ($line =~ m/Product:\s+(\S+.*)\s*$/i) {
$product = $1;
} elsif ($line =~ m/Revision:\s+(\S+.*)\s*$/i) {
$revision = $1;
} elsif ($line =~ m/Firmware Version:\s+(\S+.*)\s*$/i) {
$revision = $1;
} elsif ($line =~ m/Serial Number:\s+(\S+.*)\s*$/i) {
$serialnum = $1;
} elsif ($line =~ m/User Capacity:\s+([\d\.,]+)\s+bytes/i) {
$size = $1;
$size =~ s/[\.,]//g;
} elsif ($line =~ m/Device type:\s+(\S+.*)\s*$/i) {
$type = $1;
} elsif ($line =~ m/Model Family\s+(\S.*)\s*/i) {
$description = $1;
}
}
push (@devs, {
NAME => $devName,
MANUFACTURER => getManufacturer($vendor),
MODEL => $product,
FIRMWARE => $revision,
TYPE => $type,
DISKSIZE => $size,
SERIALNUMBER => $serialnum,
DESCRIPTION => $description
});
}
return @devs;
}
# get data from UDEV
sub getFromuDev2 {
my $params = shift;
my $common = $params->{common};
my ($devices) = @_;
my @input;
my @devs;
foreach my $device (keys %$devices) {
my $type = "";
my $model = "";
my $vendor = "";
my $firmware = "";
my $serial = "";
my $serial_short = "";
my $serial_scsi = "";
my $serial_md = "";
my $devName = $devices->{$device}->{NAME};
if ($common->can_run("udevadm")) {
@input = `udevadm info -q all -n /dev/$devName`;
} else {
@input = `udevinfo -q all -n /dev/$devName`;
}
foreach my $line (@input) {
if ($line =~ m/ID_TYPE=(\S+.*)\s*$/){
$type = $1;
} elsif ($line =~ m/ID_MODEL=(\S+.*)\s*$/) {
$model = $1;
$model =~ s/_/ /g;
} elsif ($line =~ m/ID_VENDOR=(\S+.*)\s*$/) {
$vendor = $1;
} elsif ($line =~ m/ID_REVISION=(\S+.*)\s*$/) {
$firmware = $1;
} elsif ($line =~ m/ID_SERIAL_SHORT=(\S+.*)\s*$/) {
$serial_short = $1;
} elsif ($line =~ m/ID_SCSI_SERIAL=(\S+.*)\s*$/) {
$serial_scsi = $1;
} elsif ($line =~ m/ID_SERIAL=(\S+.*)\s*$/) {
$serial = $1;
}
if ($line =~ m/MD_LEVEL=(\S+.*)\s*$/) {
$model = $1;
} elsif ($line =~ m/MD_METADATA=(\d\.?\d?)/) {
$firmware = $1;
$firmware = "MD METADATA ".$firmware;
} elsif ($line =~ m/MD_UUID=(\S+.*)\s*$/) {
$serial_md = $1;
}
}
$serial = $serial_short unless $serial_short eq ""; # prefer serial_short over serial
$serial = $serial_scsi unless $serial_scsi eq "";
$serial = $serial_md unless $serial_md eq "";
if ($devName =~ /md\d+/) { # if device is a multiple disk softraid
$type = "MD";
$vendor = "Linux";
}
push (@devs, {
NAME => $devName,
TYPE => $type,
MODEL => $model,
MANUFACTURER => getManufacturer($vendor),
FIRMWARE => $firmware,
SERIALNUMBER => $serial
});
}
return @devs;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my $devices = {};
my ($serial,$cap,$unit,$model,$manufacturer,$type,$desc,$firmware,$name);
my @partitions;
# Get complementary information in hash tab
if ($common->can_run ("lshal")) {
my %temp;
my $in = 0;
my $value;
foreach my $line (`lshal`) {
chomp $line;
if ($line =~ s{^udi = '/org/freedesktop/Hal/devices/storage.*}{}) {
$in = 1;
%temp = ();
} elsif ($in == 1 and $line =~ s{^\s+(\S+) = (.*) \s*\((int|string|bool|string list|uint64)\)}{} ) {
my $key = $1;
my $value = $2;
$value =~ s/^'(.*)'\s*$/$1/; # Drop the quote
$value =~ s/\s+$//; # Drop the trailing white space
if ($key eq 'storage.serial') {
$temp{SERIALNUMBER} = $value;
} elsif ($key eq 'storage.firmware_version') {
$temp{FIRMWARE} = $value;
} elsif ($key eq 'block.device') {
$value =~ s/\/dev\/(\S+)/$1/;
$temp{NAME} = $value;
} elsif ($key eq 'info.vendor') {
$temp{MANUFACTURER} = getManufacturer($value);
} elsif ($key eq 'storage.model') {
$temp{MODEL} = $value;
} elsif ($key eq 'storage.drive_type') {
$temp{TYPE} = $value;
} elsif ($key eq 'storage.size') {
$temp{DISKSIZE} = int($value/(1024*1024) + 0.5);
}
} elsif ($in== 1 and $line eq '' and $temp{NAME}) {
$in = 0 ;
$devices->{$temp{NAME}} = {%temp};
}
}
}
foreach my $device (getMultipathDisks($params)) {
my $name = $device->{NAME};
foreach my $f ("NAME", "MANUFACTURER", "MODEL", "SERIALNUMBER", "DESCRIPTION", "TYPE") {
$devices->{$name}->{$f} = $device->{$f};
}
}
foreach my $device (getFromDev($params)) {
my $name = $device->{NAME};
foreach my $f ("NAME") {
if($devices->{$name}->{$f} eq "") {
#debug print "getFromDev $name $f device->{\$f} $device->{$f}\n";
$devices->{$name}->{$f} = $device->{$f};
}
}
}
foreach my $device (getMdDevices($params)) {
my $name = $device->{NAME};
foreach my $f ("NAME", "MODEL") {
if ($devices->{$name}->{$f} eq "") {
$devices->{$name}->{$f} = $device->{$f};
}
}
}
foreach my $device (getFromSmartctl($params,$devices)) {
my $name = $device->{NAME};
foreach my $f ("NAME", "MANUFACTURER", "TYPE", "MODEL", "DISKSIZE", "FIRMWARE", "SERIALNUMBER", "DESCRIPTION") {
if ($devices->{$name}->{$f} eq "") {
#debug print "getFromSmartctl $name $f device->{\$f} $device->{$f}\n";
$devices->{$name}->{$f} = $device->{$f};
}
}
}
foreach my $device (getFromuDev2($params,$devices)) {
my $name = $device->{NAME};
foreach my $f ("NAME", "MANUFACTURER", "TYPE", "MODEL", "FIRMWARE", "SERIALNUMBER") {
if ($devices->{$name}->{$f} eq "") {
#debug print "getFromuDev2 $name $f device->{\$f} $device->{$f}\n";
$devices->{$name}->{$f} = $device->{$f};
}
}
}
foreach my $device (getFromLshw($params)) {
my $name = $device->{NAME};
foreach my $f ("NAME", "MANUFACTURER", "MODEL", "DESCRIPTION", "TYPE", "DISKSIZE", "SERIALNUMBER", "FIRMWARE") {
if ($devices->{$name}->{$f} eq "") {
#debug print "getFromLshw $name $f device->{\$f} $device->{$f}\n";
$devices->{$name}->{$f} = $device->{$f};
}
}
}
foreach my $device (getFromLsblk($params)) {
my $name = $device->{NAME};
foreach my $f ("NAME", "DISKSIZE", "TYPE") {
if ($devices->{$name}->{$f} eq "") {
#debug print "getFromLsblk $name $f device->{\$f} $device->{$f}\n";
$devices->{$name}->{$f} = $device->{$f};
}
}
}
foreach my $device (getFromUdev($params)) {
my $name = $device->{NAME};
foreach my $f ("NAME", "MANUFACTURER", "MODEL", "DESCRIPTION", "TYPE", "DISKSIZE", "SERIALNUMBER", "FIRMWARE", "SCSI_COID", "SCSI_CHID", "SCSI_UNID", "SCSI_LUN") {
if ($devices->{$name}->{$f} eq "") {
#debug print "getFromuDev $name $f device->{\$f} $device->{$f}\n";
$devices->{$name}->{$f} = $device->{$f};
}
}
}
foreach my $device (getFromLsscsi($params)) {
my $name = $device->{NAME};
foreach my $f ("NAME", "MANUFACTURER", "TYPE", "MODEL") {
if ($devices->{$name}->{$f} eq "") {
#debug print "getFromLsscsi $name $f device->{\$f} $device->{$f}\n";
$devices->{$name}->{$f} = $device->{$f};
}
}
}
my $logical_drive = undef;
if ($common->can_run ('arcconf') ) {
my ($cur_cont,$info,$key,$dev,$controller);
$controller = Ocsinventory::Agent::Backend::OS::Linux::Storages::Adaptec::parse_config();
foreach $cur_cont (keys %{$controller}){ #travers Controller
$info = $controller->{$cur_cont};
foreach $key (keys %{$info}){ #travers Infos of Controller
if ($key=~m/logical drive/) {
$logical_drive= $info->{$key};
}
}
}
}
foreach my $device (sort (keys %$devices)) {
if ($devices->{$device}->{TYPE} =~ /(CD)|(CD\/DVD)|(DVD)|(BD)/i) {
$devices->{$device}->{DISKSIZE} = "0000";
} elsif ($devices->{$device}->{DISKSIZE}) {
$devices->{$device}->{DISKSIZE} = $devices->{$device}->{DISKSIZE} * 10**-6; # we need MB for the view
}
if (!$devices->{$device}->{DESCRIPTION}) {
$devices->{$device}->{DESCRIPTION} = getFromSysProc($device,"description");
}
if (!$devices->{$device}->{MANUFACTURER} or $devices->{$device}->{MANUFACTURER} eq 'ATA'or $devices->{$device}->{MANUFACTURER} eq '') {
$devices->{$device}->{MANUFACTURER} = getManufacturer($devices->{$device}->{MODEL});
}
if (!$devices->{$device}->{DISKSIZE} && $devices->{$device}->{TYPE} =~ /disk/) {
$devices->{$device}->{DISKSIZE} = getCapacity($devices->{$device}->{NAME})*10**-6;
}
#if ($devices->{$device}->{CAPACITY} =~ /^cdrom$/) {
# $devices->{$device}->{CAPACITY} = getCapacity($devices->{$device}->{NAME})*10**-6;
#}
if ($devices->{$device}->{MANUFACTURER}=~m/Adaptec/) {#check if found devices are Logical Devices
foreach my $devkey (keys %{$logical_drive}) {
if($devices->{$device}->{MODEL} =~m/$logical_drive->{$devkey}->{'Logical device name'}/) { #Correct infos
$devices->{$device}->{TYPE}="Logical Drive";
$devices->{$device}->{DISKSIZE} = $logical_drive->{$devkey}->{'Size'};
}
}
}
$common->addStorages($devices->{$device});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Storages/ 0000775 0000000 0000000 00000000000 14323200667 0024543 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Storages/3ware.pm 0000664 0000000 0000000 00000014405 14323200667 0026126 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Storages::3ware;
use Ocsinventory::Agent::Backend::OS::Linux::Storages;
# Tested on 2.6.* kernels
#
# Cards tested :
#
# 8006-2LP
# 9500S-4LP
# 9550SXU-4LP
# 9550SXU-8LP
# 9650SE-2LP
# 9650SE-4LPML
# 9650SE-8LPML
#
# AMCC/3ware CLI (version 2.00.0X.XXX)
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
my ($card, $res);
# Do we have tw_cli ?
if ($common->can_run("tw_cli")) {
foreach (`tw_cli info`) {
$card = $1 if /^(c\d+).*/;
if ($card) {
$res = `tw_cli info $card numdrives`;
$card = undef;
$res =~ s/^.*=\s(\d+)/$1/;
# Do we have drives on the card ?
($res == 0)?return 0:return 1;
}
}
}
}
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my ($tw_cli, $hd);
my ($card, $card_model, $unit, $unit_id, $port, $serialnumber, $serial, $model, $capacity, $firmware, $description, $media, $device, $manufacturer, $sn);
my @devices = Ocsinventory::Agent::Backend::OS::Linux::Storages::getFromUdev();
# First, getting the cards : c0, c1... etc.
foreach (`tw_cli info`) {
# Should output something like this :
#
# Ctl Model Ports Drives Units NotOpt RRate VRate BBU
# ------------------------------------------------------------------------
# c0 9650SE-2LP 2 2 1 0 1 1 -
if (/^(c\d)+\s+([\w|-]+)/) {
$card = $1;
$card_model = $2;
$logger->debug("Card : $card - Model : $card_model");
}
if ($card) {
# Second, getting the units : u0, u1... etc.
foreach (`tw_cli info $card`) {
# Example output :
#
# Unit UnitType Status %RCmpl %V/I/M Stripe Size(GB) Cache AVrfy
# ------------------------------------------------------------------------------
# u0 RAID-1 OK - - - 65.1826 ON OFF
#
# Port Status Unit Size Blocks Serial
# ---------------------------------------------------------------
# p0 OK u0 69.25 GB 145226112 WD-WMANS1648590
# p1 OK u0 69.25 GB 145226112 WD-WMANS1344790
if (/^(u)(\d+).*/) {
$unit = $1 . $2;
$unit_id = $2;
}
if ($unit) {
# Try do get unit's serial in order to compare it to what was found in udev db.
# Works only on newer cards.
# Allow us to associate a node to a drive : sda -> WD-WMANS1648590
$sn = `tw_cli info $card $unit serial 2> /dev/null`;
$sn =~ s/^.*serial number\s=\s(\w*)\s*/$1/;
# Third, getting the ports : p0, p1... etc.
foreach(`tw_cli info $card $unit`) {
$port = $1 if /^.*(p\d+).*/;
if ($port) {
# Finally, getting drives' values.
foreach (`tw_cli info $card $port model serial capacity firmware`) {
# Example output :
#
# /c0/p0 Model = WDC WD740ADFD-00NLR4
# /c0/p0 Serial = WD-WMANS1648590
# /c0/p0 Capacity = 69.25 GB (145226112 Blocks)
# /c0/p0 Firmware Version = 21.07QR4
$model = $1 if /^.*Model\s=\s(.*)/;
$serialnumber = $1 if /^.*Serial\s=\s(.*)/;
$capacity = 1024*$1 if /^.*Capacity\s=\s(\S+)\sGB.*/;
$firmware = $1 if /^.*Firmware Version\s=\s(.*)/;
}
foreach $hd (@devices) {
# How does this work with multiple older cards where serial for units is not implemented ?
# Need to be tested on a system with multiple 3ware cards.
if (($hd->{SERIALNUMBER} eq 'AMCC_' . $sn) or ($hd->{MODEL} eq 'Logical_Disk_' . $unit_id)) {
$device = $hd->{NAME};
}
}
# Getting description from card model, very basic and unreliable
# Assuming only IDE drives can be plugged in 5xxx/6xxx cards and
# SATA drives only to 7xxx/8xxx/9xxxx cards
$description = undef;
foreach ($card_model) {
$description = "IDE" if /^[5-6].*/;
$description = "SATA" if /^[7-9].*/;
}
$media = 'disk';
$manufacturer = Ocsinventory::Agent::Backend::OS::Linux::Storages::getManufacturer($model);
$port = undef;
$logger->debug("3ware: $device, $manufacturer, $model, $description, $media, $capacity, $serialnumber, $firmware");
$common->addStorages({
NAME => $device,
MANUFACTURER => $manufacturer,
MODEL => $model,
DESCRIPTION => $description,
TYPE => $media,
DISKSIZE => $capacity,
SERIALNUMBER => $serialnumber,
FIRMWARE => $firmware,
});
}
$port = undef;
}
$unit = undef;
}
}
$card = undef;
$card_model = undef;
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Storages/Adaptec.pm 0000664 0000000 0000000 00000026110 14323200667 0026442 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Storages::Adaptec;
use Ocsinventory::Agent::Backend::OS::Linux::Storages;
#Function parse_config and parse_config_fh are taken from https://github.com/kumy/Parse-Arcconf
#
#LICENSE AND COPYRIGHT
#
#Copyright (C) 2012 Mathieu Alorent
#
#This program is free software; you can redistribute it and/or modify it
#under the terms of either: the GNU General Public License as published
#by the Free Software Foundation; or the Artistic License.
#
#See http://dev.perl.org/licenses/ for more information.
# Tested on 2.6.* kernels
#
# Cards tested :
#
# Adaptec AAC-RAID
use strict;
my @devices = Ocsinventory::Agent::Backend::OS::Linux::Storages::getFromUdev();
sub check {
my $params = shift;
my $common = $params->{common};
#Do we have arcconf
if ($common->can_run ('arcconf') ) {
my $conf = `arcconf GETCONFIG 1`;
if($conf =~ /Controllers found: (\d+)/) {
if($1>0) {
return 1;
}
}
}
#Do we have smartctl
if ($common->can_run ('smartctl') ) {
foreach my $hd (@devices) {
$hd->{MANUFACTURER} eq 'Adaptec'?return 1:1;
}
}
return 0;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my ($name,$vendor,$model,$serialnumber,$firmware, $size, $description, $media, $manufacturer);
my ($conf, $cur_cont,$info,$key, $dev, $devkey,$controller);
#get infos from arcconf if possible
if ($common->can_run ('arcconf') ) {
$conf = `arcconf GETCONFIG 1`;
if($conf =~ /Controllers found: (\d+)/) {
if($1>0) {
$controller = parse_config();
foreach $cur_cont (keys %{$controller}){ #travers Controller
$info = $controller->{$cur_cont};
foreach $key (keys %{$info}){ #travers Infos of Controller
#physical drives
if ($key=~m/physical drive/) {
$dev = $info->{$key};
foreach $devkey (keys %{$dev}) { #get infos
$vendor = $dev->{$devkey}->{'Vendor'};
$model = $dev->{$devkey}->{'Model'};
$serialnumber = $dev->{$devkey}->{'Serial number'};
$firmware = $dev->{$devkey}->{'Firmware'};
$size = $dev->{$devkey}->{'Size'};
$description = $dev->{$devkey}->{'Transfer Speed'};
$media = $dev->{$devkey}->{'Device is'};
unless ( $media=~m/an Enclosure services device/) { #Dont need services device just drives
if ( $media=~m/a Hard drive/ ){
$media = "HDD";
#try to determine if Drive is a Solid State Disk
if (exists $dev->{$devkey}->{'SSD'}) { #SSD Info is explicit in config
my $ssd = $dev->{$devkey}->{'SSD'};
if ($ssd=~m/Yes/) {
$media = "SSD";
}
} else { #No explicit info try to get it through model name
if($model =~m/SSD|Solid State|WDS/) {
$media = "SSD";
}
}
}
$manufacturer = Ocsinventory::Agent::Backend::OS::Linux::Storages::getManufacturer($vendor);
$logger->debug("Adaptec: $manufacturer $media $size, $manufacturer, $model, $description, $media, $size , $serialnumber, $firmware");
$common->addStorages({
NAME => "$manufacturer $media $size",
MANUFACTURER => $manufacturer,
MODEL => $model,
DESCRIPTION => $description,
TYPE => $media,
DISKSIZE => $size,
SERIALNUMBER => $serialnumber,
FIRMWARE => $firmware,
});
}
}
}
}
}
}
}
}
elsif (-r '/proc/scsi/scsi') {
foreach my $hd (@devices) {
open (PATH, '/proc/scsi/scsi');
# Example output:
#
# Attached devices:
# Host: scsi0 Channel: 00 Id: 00 Lun: 00
# Vendor: Adaptec Model: raid10 Rev: V1.0
# Type: Direct-Access ANSI SCSI revision: 02
# Host: scsi0 Channel: 01 Id: 00 Lun: 00
# Vendor: HITACHI Model: HUS151436VL3800 Rev: S3C0
# Type: Direct-Access ANSI SCSI revision: 03
# Host: scsi0 Channel: 01 Id: 01 Lun: 00
# Vendor: HITACHI Model: HUS151436VL3800 Rev: S3C0
# Type: Direct-Access ANSI SCSI revision: 03
my ($host, $model, $firmware, $manufacturer, $size, $serialnumber);
my $count = -1;
while () {
($host, $count) = (1, $count+1) if /^Host:\sscsi$hd->{SCSI_COID}.*/;
if ($host) {
if ((/.*Model:\s(\S+).*Rev:\s(\S+).*/) and ($1 !~ 'raid.*')) {
$model = $1;
$firmware = $2;
$manufacturer = Ocsinventory::Agent::Backend::OS::Linux::Storages::getManufacturer($model);
foreach (`smartctl -i /dev/sg$count`) {
$serialnumber = $1 if /^Serial Number:\s+(\S*).*/;
}
$logger->debug("Adaptec: $hd->{NAME}, $manufacturer, $model, SATA, disk, $hd->{DISKSIZE}, $serialnumber, $firmware");
$host = undef;
$common->addStorages({
NAME => $hd->{NAME},
MANUFACTURER => $manufacturer,
MODEL => $model,
DESCRIPTION => 'SATA',
TYPE => 'disk',
DISKSIZE => $size,
SERIALNUMBER => $serialnumber,
FIRMWARE => $firmware,
});
}
}
}
close (PATH);
}
}
}
sub parse_config
{
my $arcconf = "arcconf";
my $argument = "GETCONFIG 1";
my $command = sprintf("%s %s|", $arcconf, $argument);
my $fh;
if(open $fh, $command)
{
my $c = parse_config_fh($fh);
close $fh;
return $c;
}
return undef;
}
sub parse_config_fh
{
my $fh = $_[0];
my $controller = {};
my $total_controller = 0;
my $current_controller = 0;
my $current_logical_drive = undef;
my $current_physical_drive = undef;
my $ctrl = undef;
my $line = undef;
LEVEL1: while($line = <$fh>)
{
chomp $line;
next if($line =~ /^$/);
next if($line =~ /^-+$/);
if($line =~ /^Controllers found: (\d+)$/) {
$total_controller = $1;
}
if($line =~ /^Controller information/) {
$current_controller = $current_controller + 1;
$current_logical_drive = undef;
$current_physical_drive = undef;
$controller->{$current_controller} = {};
$ctrl = $controller->{$current_controller};
while($line = <$fh>) {
chomp $line;
if ($line =~ /^\s+(.*\w)\s+:\s+(.*)$/) {
$ctrl->{$1} = $2;
} elsif ($line =~ /^\s+-+$/) {
last;
}
}
LEVEL2: while($line = <$fh>) {
if ($line =~ /^\s+-+$/) {
$line = <$fh>;
chomp $line;
}
if($line =~ /^\s+(.*\w)\s*/) {
my $cat = $1;
$line = <$fh>;
LEVEL3: while($line = <$fh>) {
chomp $line;
if ($line =~ /^\s+(.*\w)\s+:\s+(.*)$/) {
$ctrl->{$cat}{$1} = $2;
} elsif ($line =~ /^\s+-+$/) {
last LEVEL3;
} elsif ($line =~ /^$/) {
last LEVEL2;
}
}
}
}
}
next if(!defined($current_controller));
if($line =~ /^Logical drive information/ or $line =~ /^Logical device information/) {
LEVEL4: while($line = <$fh>) {
chomp $line;
if ($line =~ /^\S+.*\w\s+(\d+)$/) {
$current_logical_drive = $1;
} elsif ($line =~ /^\s+(\S.*\S+)\s+:\s+(.*)$/) {
$ctrl->{'logical drive'}{$current_logical_drive}{$1} = $2;
} elsif ($line =~ /^\s+-+$/) {
my $cat = <$fh>;
$cat =~ s/^\s+(\S.*\S+)\s+/$1/;
chomp $cat;
LEVEL5: while($line = <$fh>) {
chomp $line;
if ($line =~ /^\s+(\S.*\S+)\s+:\s+(.*)$/) {
$ctrl->{'logical drive'}{$current_logical_drive}{$cat}{$1} = $2;
} elsif ($line =~ /^\S+.*\w\s+(\d+)$/) {
$current_logical_drive = $1;
last LEVEL5;
} elsif ($line =~ /^-+$/) {
last LEVEL4;
} elsif ($line =~ /^\s+-+$/) {
next;
}
}
}
}
}
if($line =~ /^Physical Device information/) {
LEVEL2: while($line = <$fh>) {
if ($line =~ /^\s+-+$/) {
$line = <$fh>;
chomp $line;
}
if ($line =~ /^\s+Device\s+#(\d+)$/) {
$current_physical_drive = $1;
} elsif ($line =~ /^\s+Device is (.*\w)/) {
$ctrl->{'physical drive'}{$current_physical_drive}{'Device is'} = $1;
} elsif ($line =~ /^\s+(.*\w)\s+:\s+(.*)$/) {
$ctrl->{'physical drive'}{$current_physical_drive}{$1} = $2;
} elsif ($line =~ /^\s+-+$/) {
last LEVEL3;
} elsif ($line =~ /^$/) {
last LEVEL2;
}
}
}
}
return $controller;
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Storages/FusionIO.pm 0000664 0000000 0000000 00000003405 14323200667 0026576 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Storages::FusionIO;
use Ocsinventory::Agent::Backend::OS::Linux::Storages;
use strict;
sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };
sub check {
my $params = shift;
my $common = $params->{common};
my $ret;
# Do we have fio-status?
if ($common->can_run("fio-status")) {
foreach (`fio-status 2> /dev/null`) {
if (/^fct(\d*).*/) {
$ret=1;
last;
}
}
}
return $ret;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my ($pd, $serialnumber, $model, $capacity, $firmware, $description, $media, $manufacturer);
foreach (`fio-status 2> /dev/null`) {
if (/^fct(\d*).*/) {
my $slot = $1;
my $cmd = "fio-status /dev/fct$slot --field";
$model = trim(`$cmd iom.board_name`);
$description = trim(`$cmd adapter.product_name`);
$media = trim('disk');
$capacity = trim(`$cmd iom.size_bytes`);
$serialnumber = 'OEM:'.trim(`$cmd adapter.oem_serial_number`).' FIO:'.trim(`$cmd adapter.fio_serial_number`).' IOM:'.trim(`$cmd iom.serial_number`);
$firmware = trim(`$cmd iom.fw_current_version`.' rev '.`$cmd iom.fw_current_revision`);
$logger->debug("Fusion-io: N/A, $manufacturer, $model, $description, $media, $capacity, $serialnumber, $firmware");
$common->addStorages({
NAME => $model,
MANUFACTURER => 'Fusion-io',
MODEL => $model,
DESCRIPTION => $description,
TYPE => $media,
DISKSIZE => $capacity,
SERIALNUMBER => $serialnumber,
FIRMWARE => $firmware
});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Storages/HP.pm 0000664 0000000 0000000 00000010531 14323200667 0025410 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Storages::HP;
use Ocsinventory::Agent::Backend::OS::Linux::Storages;
# Tested on 2.6.* kernels
#
# Cards tested :
#
# Smart Array E200
#
# HP Array Configuration Utility CLI 7.85-18.0
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
my $ret;
# Do we have ssacli ?
if ($common->can_run("ssacli")) {
foreach (`ssacli ctrl all show 2> /dev/null`) {
if (/.*Slot\s(\d*).*/) {
$ret = 1;
last;
}
}
}
return $ret;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my ($pd, $serialnumber, $model, $capacity, $firmware, $description, $media, $manufacturer);
foreach (`ssacli ctrl all show 2> /dev/null`) {
# Example output :
#
# Smart Array E200 in Slot 2 (sn: PA6C90K9SUH1ZA)
if (/.*Slot\s(\d*).*/) {
my $slot = $1;
foreach (`ssacli ctrl slot=$slot pd all show 2> /dev/null`) {
# Example output :
# Smart Array E200 in Slot 2
#
# array A
#
# physicaldrive 2I:1:1 (port 2I:box 1:bay 1, SATA, 74.3 GB, OK)
# physicaldrive 2I:1:2 (port 2I:box 1:bay 2, SATA, 74.3 GB, OK)
if (/.*physicaldrive\s(\S*)/) {
my $pd = $1;
foreach (`ssacli ctrl slot=$slot pd $pd show 2> /dev/null`) {
# Example output :
#
# Smart Array E200 in Slot 2
#
# array A
#
# physicaldrive 1:1
# Port: 2I
# Box: 1
# Bay: 1
# Status: OK
# Drive Type: Data Drive
# Interface Type: SATA
# Size: 74.3 GB
# Firmware Revision: 21.07QR4
# Serial Number: WD-WMANS1732855
# Model: ATA WDC WD740ADFD-00
# SATA NCQ Capable: False
# PHY Count: 1
$model = $1 if /.*Model:\s(.*)/;
$description = $1 if /.*Interface Type:\s(.*)/;
$media = $1 if /.*Drive Type:\s(.*)/;
$capacity = $1 if /^\s*Size:\s(.*)/;
$serialnumber = $1 if /.*Serial Number:\s(.*)/;
$firmware = $1 if /.*Firmware Revision:\s(.*)/;
}
$serialnumber =~ s/^\s+//;
$model =~ s/^ATA\s+//; # ex: ATA WDC WD740ADFD-00
$model =~ s/\s+/ /;
$manufacturer = Ocsinventory::Agent::Backend::OS::Linux::Storages::getManufacturer($model);
if ($media eq 'Data Drive') {
$media = 'HDD';
if ($description =~m/SSD|Solid State/) {
$media = 'SSD';
} elsif ($model =~m/SSD|Solid State|WDS/) {
$media = 'SSD';
}
}
if ($capacity =~m/TB/) {
$capacity *= 1000000;
} elsif ($capacity =~m/GB/) {
$capacity *= 1000;
} else {
$capacity *= 1;
}
$logger->debug("HP: N/A, $manufacturer, $model, $description, $media, $capacity, $serialnumber, $firmware");
$common->addStorages({
NAME => $model,
MANUFACTURER => $manufacturer,
MODEL => $model,
DESCRIPTION => $description,
TYPE => $media,
DISKSIZE => $capacity,
SERIALNUMBER => $serialnumber,
FIRMWARE => $firmware
});
}
}
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Storages/Lsilogic.pm 0000664 0000000 0000000 00000005135 14323200667 0026652 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Storages::Lsilogic;
use Ocsinventory::Agent::Backend::OS::Linux::Storages;
# Tested on 2.6.* kernels
#
# Cards tested :
#
# LSI Logic / Symbios Logic SAS1064E PCI-Express Fusion-MPT SAS
#
# mpt-status version : 1.2.0
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
my $device;
# Do we have smartctl ?
if ($common->can_run('smartctl')) {
foreach my $node (glob("/dev/sd?")) {
foreach (`smartctl -i $node`) {
$device = $1 if /.*Device:\s(\w*).*/;
}
}
($device eq 'LSILOGIC')?return 1:return 0;
}
return 0;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my $serialnumber;
my @devices = Ocsinventory::Agent::Backend::OS::Linux::Storages::getFromUdev();
foreach my $hd (@devices) {
foreach (`mpt-status -n -i $hd->{SCSI_UNID}`) {
# Example output :
#
# ioc:0 vol_id:0 type:IM raidlevel:RAID-1 num_disks:2 size(GB):148 state: OPTIMAL flags: ENABLED
# ioc:0 phys_id:1 scsi_id:2 vendor:ATA product_id:ST3160815AS revision:D size(GB):149 state: ONLINE flags: NONE sync_state: 100 ASC/ASCQ:0xff/0xff SMART ASC/ASCQ:0xff/0xff
#ioc:0 phys_id:0 scsi_id:1 vendor:ATA product_id:ST3160815AS revision:D size(GB):149 state: ONLINE flags: NONE sync_state: 100 ASC/ASCQ:0xff/0xff SMART ASC/ASCQ:0xff/0xff
#scsi_id:1 100%
#scsi_id:0 100%
if (/.*phys_id:(\d+).*product_id:\s*(\S*)\s+revision:(\S+).*size\(GB\):(\d+).*/) {
$serialnumber = undef;
foreach (`smartctl -i /dev/sg$1`) {
$serialnumber = $1 if /^Serial Number:\s+(\S*)/;
}
my $model = $2;
my $size = 1024*$4; # GB => MB
my $firmware = $3;
my $manufacturer = Ocsinventory::Agent::Backend::OS::Linux::Storages::getManufacturer($model);
$logger->debug("Lsilogic: $hd->{NAME}, $manufacturer, $model, SATA, disk, $size, $serialnumber, $firmware");
$common->addStorages({
NAME => $hd->{NAME},
MANUFACTURER => $manufacturer,
MODEL => $model,
DESCRIPTION => 'SATA',
TYPE => 'disk',
DISKSIZE => $size,
SERIALNUMBER => $serialnumber,
FIRMWARE => $firmware,
});
}
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Storages/Megacli.pm 0000664 0000000 0000000 00000005210 14323200667 0026440 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Storages::Megacli;
use Ocsinventory::Agent::Backend::OS::Linux::Storages;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
my $ret;
my $cont;
if ($common->can_run("megacli")) {
foreach (`megacli -adpCount 2>/dev/null`) {
if (/^Controller\sCount:\s(\d+)/) {
$cont=$1;
if (defined $cont && $cont == 1) {
$ret=1;
last;
}
}
}
}
return $ret;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my $adpc;
my $model;
my $description;
my $capacity;
my $firmware;
my $serial;
my $manufacturer;
my $index;
my @partitions;
my @sl;
# Retrieve the partition
open PARTINFO, '){
if (/^\s*(\d*)\s*(\d*)\s*(\d*)\s*([sh]d[a-z]+)$/i){
push(@partitions,$4);
}
}
# How adapters are present?
foreach (`megacli -adpCount 2> /dev/null`){
$adpc=$1 if (/^Controller Count:\s(\d+)./i);
}
# How slot are used on the controller?
for (my $count=0;$count<$adpc;$count++){
foreach (`megacli -ShowSummary -a$count`){
# Slot number : Connector : 0: Slot 1
if (/Connector\s*:\s*\d+(?:): Slot (\d+)/){
push (@sl, $1);
}
}
# use smartctcl command to retrieve information
foreach my $dev (@partitions){
foreach my $slo (@sl){
# smartctl -i -d megaraid,0 /dev/sda
my $result=`smartctl -i -d megaraid,$slo /dev/$dev`;
$model=$1 if ($result =~ /Model Family:\s*(.*)/);
$description=$1 if ($result =~ /Device Model:\s*(.*)/);
$manufacturer = Ocsinventory::Agent::Backend::OS::Linux::Storages::getManufacturer($description);
$serial=$1 if ($result =~ /Serial Number:\s*(.*)/);
$firmware=$1 if ($result =~ /Firmware Version:\s*(.*)/);
$capacity=$1 if ($result =~ /User Capacity:\s*.*\[(.*)\]/);
$common->addStorages({
NAME => $description,
MANUFACTURER => $manufacturer,
MODEL => $model,
DESCRIPTION => $description,
TYPE => "Disk",
DISKSIZE => $capacity,
SERIALNUMBER => $serial,
FIRMWARE => $firmware
});
}
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Storages/ServeRaid.pm 0000664 0000000 0000000 00000007314 14323200667 0026772 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Storages::ServeRaid;
use Ocsinventory::Agent::Backend::OS::Linux::Storages;
# Tested on 2.6.* kernels
#
# Cards tested :
#
# IBM ServeRAID-6M
# IBM ServeRAID-6i
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
my $ret = 0;
# Do we have ipssend installed ?
if ($common->can_run("ipssend")) {
foreach (`ipssend GETVERSION 2>/dev/null`) {
if (/.*ServeRAID Controller Number\s(\d*).*/) {
$ret = $1;
last;
}
}
}
return $ret;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my $slot;
$logger->debug("ServeRaid: ipssend GETVERSION");
foreach (`ipssend GETVERSION 2>/dev/null`) {
# Example Output :
# Found 1 IBM ServeRAID controller(s).
#----------------------------------------------------------------------
#ServeRAID Controller(s) Version Information
#----------------------------------------------------------------------
# Controlling BIOS version : 7.00.14
#
#ServeRAID Controller Number 1
# Controller type : ServeRAID-6M
# Controller slot information : 2
# Actual BIOS version : 7.00.14
# Firmware version : 7.00.14
# Device driver version : 7.10.18
$slot = $1 if /.*ServeRAID Controller Number\s(\d*).*/;
if (/.*Controller type.*:\s(.*)/) {
my $name = $1;
my ($serial, $capacity, $scsi, $channel, $state);
$logger->debug("ServeRaid: ipssend GETCONFIG $slot PD");
foreach (`ipssend GETCONFIG $slot PD 2>/dev/null`) {
# Example Output :
# Channel #1:
# Target on SCSI ID 0
# Device is a Hard disk
# SCSI IDg: 0
# PFA (Yes/No) : No
# Stateg : Online (ONL)
# Size (in MB)/(in sectors): 34715/71096368
# Device ID : IBM-ESXSCBR036C3DFQDB2Q6CDKM
# FRU part number : 32P0729
$channel = $1 if /.*Channel #(.*):/;
$scsi = $1 if /.*SCSI ID.*:\s(.*)/;
$state = $1 if /.*State.*\((.*)\)/;
$capacity = $1 if /.*Size.*:\s(\d*)\/(\d*)/;
$serial = $1 if /.*Device ID.*:\s(.*)/;
if (/.*FRU part number.*:\s(.*)/) {
my $model = $1;
my $manufacturer = Ocsinventory::Agent::Backend::OS::Linux::Storages::getManufacturer($serial);
## my $fullname = "$name $slot/$channel/$scsi $state";
$logger->debug("ServeRaid: found $model, $manufacturer, $model, SCSI, disk, $capacity, $serial, ");
$common->addStorages({
NAME => "$manufacturer $model",
MANUFACTURER => $manufacturer,
MODEL => $model,
DESCRIPTION => "SCSI",
TYPE => "disk",
DISKSIZE => $capacity,
SERIALNUMBER => $serial,
FIRMWARE => ""
});
# don't undef $channel, appear only once for several drive.
$scsi = $state = $capacity = $serial = undef;
}
}
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Sys.pm 0000664 0000000 0000000 00000000525 14323200667 0024072 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Sys;
#$LunchAfter = "Ocsinventory::Agent::Backend::OS::Linux::VirtualFs::Sys";
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run ("mount");
foreach (`mount`) {
return 1 if (/type\ sysfs/);
}
0;
}
sub run {}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Uptime.pm 0000664 0000000 0000000 00000001504 14323200667 0024555 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Uptime;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_read("/proc/uptime")
}
sub run {
my $params = shift;
my $common = $params->{common};
# Uptime
open UPTIME, "/proc/uptime";
my $uptime = ;
$uptime =~ s/^(.+)\s+.+/$1/;
close UPTIME;
# Uptime conversion
my ($UYEAR, $UMONTH , $UDAY, $UHOUR, $UMIN, $USEC) = (gmtime ($uptime))[5,4,3,2,1,0];
# Write in ISO format
$uptime=sprintf "%02d-%02d-%02d %02d:%02d:%02d", ($UYEAR-70), $UMONTH, ($UDAY-1), $UHOUR, $UMIN, $USEC;
chomp(my $DeviceType =`uname -m`);
# TODO$h->{'CONTENT'}{'HARDWARE'}{'DESCRIPTION'} = [ "$DeviceType/$uptime" ];
$common->setHardware({ DESCRIPTION => "$DeviceType/$uptime" });
}
1
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Linux/Videos.pm 0000664 0000000 0000000 00000003575 14323200667 0024555 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Linux::Videos;
use strict;
use warnings;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run ("nvidia-smi");
return unless $common->can_run ("nvidia-settings");
}
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my $nvidia;
my @nvidia_infos=`nvidia-smi -q`;
my @nvidia_settings=`nvidia-settings -q all`;
my @prime=`nvidia-settings --query=PrimeOutputsData`;
foreach my $info (@nvidia_infos) {
$nvidia->{SERIALNUMBER}=$1 if ($info =~ /Serial Number\s+: (.*)/i);
$nvidia->{DRVVERSION}=$1 if ($info =~ /Driver Version\s+: ([0-9]+\.[0-9]+)/i);
$nvidia->{NBGPU}=$1 if ($info =~ /Attached GPUs\s+: ([0-9])/i);
$nvidia->{VBIOS}=$1 if ($info =~ /VBIOS Version\s+: (.*)/i);
$nvidia->{NAME}=$1 if ($info =~ /Product Name\s+:(.*)/i);
$nvidia->{UUID}=$1 if ($info =~ /GPU UUID\s+:(.*)/i);
$nvidia->{PCISLOT}=$1 if ($info =~ /Bus Id\s+:(.*)/i);
}
# Resolution
foreach my $inf (@prime) {
next if ($inf =~ /^\s*$/);
my $width=$1 if ($inf =~ /width=(\d{1,4})/);
my $height=$1 if ($inf =~ /height=(\d{1,4})/);
$nvidia->{RESOLUTION}=$width."x".$height;
}
$nvidia->{MEMORY}=`nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits`;
$nvidia->{MEMORY} =~ s/\s+$//g;
$nvidia->{NAME} =~ s/^\s//g;
$nvidia->{UUID} =~ s/^\s//g;
$nvidia->{PCISLOT} =~ s/^\s0{8}://g;
foreach my $settings (@nvidia_settings) {
$nvidia->{DATA_WIDTH}=$1 if ($settings =~ /Attribute \'GPUMemoryInterface\'\s\(.*\):\s(\d{2})./i);
$nvidia->{CUDACORES}=$1 if ($settings =~ /Attribute \'CUDACores\'\s\(.*\):\s(\d{2})./i);
}
for (my $i=0; $i<$nvidia->{NBGPU};$i++) {
$common->addVideo($nvidia);
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS.pm 0000664 0000000 0000000 00000003273 14323200667 0023162 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS;
use strict;
require Exporter;
our @ISA = qw /Exporter/;
our @EXPORT = qw /get_sysprofile_devices_names/;
sub check {
my $r;
# we check far darwin because that's the _real_ underlying OS
$r = 1 if (uc($^O) =~ /^DARWIN$/);
return($r);
}
sub run {
my $params = shift;
my $common = $params->{common};
my $OSName;
my $OSComment;
my $OSVersion;
my $uuid;
# if we can load the system profiler, gather the information from that
if ($common->can_load("Mac::SysProfile")){
my $profile = Mac::SysProfile->new();
my $data = $profile->gettype('SPSoftwareDataType');
return(undef) unless(ref($data) eq 'ARRAY');
my $h = $data->[0];
my $SystemVersion = $h->{'os_version'};
if ($SystemVersion =~ /^(.*?)\s+(\d+.*)/) {
$OSName=$1;
$OSVersion=$2;
} else {
# Default values
$OSName="macOS";
$OSVersion="Unknown";
}
} else {
# we can't load the system profiler, use the basic BSD stype information
# Operating system informations
chomp($OSName=`uname -s`);
chomp($OSVersion=`uname -r`);
}
# add the uname -v as the comment, not really needed, but extra info never hurt
chomp($OSComment=`uname -v`);
# We get UUID
if ($common->can_run("ioreg")) {
my @ioreg = split ("=", `ioreg -rd1 -c IOPlatformExpertDevice | grep -E '(UUID)'`);
chomp($uuid = $ioreg[1]);
$uuid =~ s/\"|\s//g;
}
$common->setHardware({
OSNAME => $OSName,
OSCOMMENTS => $OSComment,
OSVERSION => $OSVersion,
UUID => $uuid,
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/ 0000775 0000000 0000000 00000000000 14323200667 0022617 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/Bios.pm 0000664 0000000 0000000 00000002373 14323200667 0024056 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::Bios;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return $common->can_load("Mac::SysProfile")
}
sub run {
my $params = shift;
my $common = $params->{common};
# use Mac::SysProfile to get the respected datatype
my $profile = Mac::SysProfile->new();
my $data = $profile->gettype('SPHardwareDataType');
# unless we get a real hash value, return with nothing
return(undef) unless($data && ref($data) eq 'ARRAY');
my $h = $data->[0];
# set the bios information from the apple system profiler
$common->setBios({
SMANUFACTURER => 'Apple Inc', # duh
SMODEL => $h->{'model_identifier'} || $h->{'machine_model'},
TYPE => $h->{'machine_name'},
BMANUFACTURER => 'Apple Inc',
MMANUFACTURER => 'Apple Inc',
# SSN => $h->{'Serial Number'}
# New method to get the SSN, because of MacOS 10.5.7 update
# system_profiler gives 'Serial Number (system): XXXXX' where 10.5.6
# and lower give 'Serial Number: XXXXX'
SSN => $h->{'serial_number'},
BVERSION => $h->{'boot_rom_version'},
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/CPU.pm 0000664 0000000 0000000 00000004066 14323200667 0023612 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::CPU;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return(undef) unless -r '/usr/sbin/system_profiler';
return(undef) unless $common->can_load("Mac::SysProfile");
return 1;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $processors;
my $arch;
my $datawidth;
# 32 or 64 bits arch?
my $sysctl_arch = `sysctl -n hw.cpu64bit_capable`;
if ($sysctl_arch == 1){
$arch = "x86_64";
$datawidth = 64;
} else {
$arch = "x86";
$datawidth = 32;
}
# How much processor socket ?
my $ncpu=`sysctl -n hw.packages`;
# For each processor socket
foreach my $cpu (1..$ncpu) {
$processors->{$cpu}->{MANUFACTURER} = `sysctl -n machdep.cpu.vendor`;
if ($processors->{$cpu}->{MANUFACTURER} =~ /(Authentic|Genuine|)(.+)/i) {
$processors->{$cpu}->{MANUFACTURER} = $2;
}
chomp($processors->{$cpu}->{MANUFACTURER} );
$processors->{$cpu}->{TYPE} = `sysctl -n machdep.cpu.brand_string`;
chomp($processors->{$cpu}->{TYPE} );
$processors->{$cpu}->{SPEED} = `sysctl -n hw.cpufrequency` / 1000 / 1000;
$processors->{$cpu}->{L2CACHESIZE} = `sysctl -n hw.l2cachesize` / 1024;
$processors->{$cpu}->{CORES} = `sysctl -n machdep.cpu.core_count`;
chomp($processors->{$cpu}->{CORES});
$processors->{$cpu}->{THREADS} = `sysctl -n machdep.cpu.thread_count`;
chomp($processors->{$cpu}->{THREADS});
$processors->{$cpu}->{LOGICAL_CPUS} = `sysctl -n machdep.cpu.logical_per_package`;
chomp($processors->{$cpu}->{LOGICAL_CPUS});
$processors->{$cpu}->{CPUARCH} = $arch;
$processors->{$cpu}->{DATA_WIDTH} = $datawidth;
$processors->{$cpu}->{NBSOCKET} = $cpu;
chomp($processors->{$cpu}->{NBSOCKET});
$processors->{$cpu}->{SERIALNUMBER} = "N/A";
}
# Add new cpu infos to inventory
foreach (keys %{$processors}){
$common->addCPU($processors->{$_});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/Camera.pm 0000664 0000000 0000000 00000001104 14323200667 0024341 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::Camera;
use strict;
sub check {
return(undef) unless -r '/usr/sbin/system_profiler'; # check perms
return 1;
}
sub run {
my $params = shift;
my $common = $params->{common};
# create profiler obj, bail if datatype fails
my $data = $common->get_sysprofile_devices_names('SPCameraDataType');
return(undef) unless(ref($data) eq 'ARRAY');
# add sound cards
foreach my $cam (@$data){
$common->addCamera({
'MODEL' => $cam,
'UUID' => $cam,
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/Controllers.pm 0000664 0000000 0000000 00000004560 14323200667 0025470 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::Controllers;
sub check {
my $params = shift;
my $common = $params->{common};
return(undef) unless -r '/usr/sbin/system_profiler'; # check perms
return (undef) unless $common->can_load("Mac::SysProfile");
return 1;
}
sub run {
my $params = shift;
my $common = $params->{common};
my ($caption, $description, $name, $type);
my $datatypes = {
#usb => 'SPUSBDataType', TODO: fix problems with SPUSBDataType in Mac::Sysprofile
firewire => 'SPFireWireDataType',
thunderbolt => 'SPThunderboltDataType',
ethernet => 'SPEthernetDataType',
};
for my $datatype (keys %$datatypes) {
# create the profile object and return undef unless we get something back
my $pro = Mac::SysProfile->new();
my $data = $pro->gettype($datatypes->{$datatype});
return(undef) unless(ref($data) eq 'ARRAY');
foreach my $port (@$data) {
if ($datatype =~ /usb/) {
$name = $port->{'usb_bus_number'};
$type = 'USB Bus';
$description = $port->{'controller_location'} . ", PCI Device ID: " . $port->{'pci_device'};
} elsif ($datatype =~ /firewire/) {
$name = 'FireWire';
$type = 'FireWire Bus';
$description = 'Max Speed: ' . $port->{'max_device_speed'};
} elsif ($datatype =~ /thunderbolt/) {
$name = $port->{'device_name_key'};
next unless $name;
$type = 'Thunderbolt';
$description = 'UID: ' . $port->{'switch_uid_key'};
} elsif ($datatype =~ /ethernet/) {
$name = $port->{'_name'};
if ($name ne '') {
$name = $port->{'spethernet_device-id'} if ($name eq 'ethernet');
$type = 'Ethernet Controller';
$description = 'BSD: ' . $port->{'spethernet_BSD_Name'};
}
}
$common->addController({
CAPTION => $caption,
DESCRIPTION => $description,
NAME => $name,
TYPE => $type,
});
$caption = $description = $name = $type = undef;
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/Domains.pm 0000664 0000000 0000000 00000001373 14323200667 0024553 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::Domains;
use strict;
# straight up theft from the other modules...
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run('dsconfigad');
my @domain = `dsconfigad -show`;
return 1 if @domain;
0
}
sub run {
my $params = shift;
my $common = $params->{common};
my $domain;
my $domainInfo;
chomp ($domainInfo = `dsconfigad -show`);
my @domainInfo = split (/\n/, $domainInfo);
shift(@domainInfo);
if($domainInfo[0]) {
@domainInfo = split(/\=/, $domainInfo[0]);
$domain = $domainInfo[1];
$domain =~ s/^\s+//;
}
$common->setHardware({
WORKGROUP => $domain
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/Drives.pm 0000664 0000000 0000000 00000002115 14323200667 0024410 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::Drives;
use strict;
# yea BSD theft!!!!
# would have used Mac::SysProfile, but the xml isn't quite fully supported
# the drives come back in apple xml tree's, and the module can't handle it yet (soon as I find the time to fix the patch)
sub check {1}
sub run {
my $params = shift;
my $common = $params->{common};
my $free;
my $filesystem;
my $total;
my $type;
my $volumn;
for my $t ("apfs", "ffs","ufs", "hfs") {
# OpenBSD has no -m option so use -k to obtain results in kilobytes
for(`df -P -k -t $t`){ # darwin needs the -t to be last
if(/^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\n/){
$type = $1;
$filesystem = $t;
$total = sprintf("%i",$2/1024);
$free = sprintf("%i",$4/1024);
$volumn = $6;
$common->addDrive({
FREE => $free,
FILESYSTEM => $filesystem,
TOTAL => $total,
TYPE => $type,
VOLUMN => $volumn
})
}
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/Hostname.pm 0000664 0000000 0000000 00000001103 14323200667 0024726 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::Hostname;
sub check {
my $params = shift;
my $common = $params->{common};
return 1 if $common->can_load ("Mac::SysProfile");
0;
}
# Initialise the distro entry
sub run {
my $params = shift;
my $common = $params->{common};
my $hostname;
my $profile = Mac::SysProfile->new();
my $data = $profile->gettype('SPSoftwareDataType');
return undef unless(ref($data) eq 'ARRAY');
my $h = $data->[0];
$hostname = $h->{'local_host_name'};
$common->setHardware ({NAME => $hostname}) if $hostname;
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/IPv4.pm 0000664 0000000 0000000 00000001121 14323200667 0023732 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::IPv4;
# straight up theft from the other modules
sub check {
my @ifconfig = `ifconfig -a 2>/dev/null`;
return 1 if @ifconfig;
return;
}
# Initialise the distro entry
sub run {
my $params = shift;
my $common = $params->{common};
my @ip;
# Looking for ip addresses with ifconfig, except loopback
# *BSD need -a option
foreach (`ifconfig -a`){
if(/^\s*inet\s+(\S+)/){
($1=~/^127.+/)?next:push @ip, $1
};
}
my $ip=join "/", @ip;
$common->setHardware({IPADDR => $ip});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/Mem.pm 0000664 0000000 0000000 00000004746 14323200667 0023706 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::Mem;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return(undef) unless -r '/usr/sbin/system_profiler'; # check perms
return (undef) unless $common->can_load("Mac::SysProfile");
return 1;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $PhysicalMemory;
# create the profile object and return undef unless we get something back
my $profile = Mac::SysProfile->new();
my $data = $profile->gettype('SPMemoryDataType');
return(undef) unless(ref($data) eq 'ARRAY');
# Workaround for MacOSX 10.5.7
#if ($h->{'Memory Slots'}) {
# $h = $h->{'Memory Slots'};
#}
foreach my $memory (@$data){
next unless $memory->{'_name'} =~ /^BANK|SODIMM|DIMM/;
# tare out the slot number
my $slot = $memory->{'_name'};
# memory in 10.5
if($slot =~ /^BANK (\d)\/DIMM\d/){
$slot = $1;
}
# 10.4
if($slot =~ /^SODIMM(\d)\/.*$/){
$slot = $1;
}
# 10.4 PPC
if($slot =~ /^DIMM(\d)\/.*$/){
$slot = $1;
}
# 10.7
if ($slot =~ /^DIMM (\d)/) {
$slot = $1;
}
my $size = $memory->{'dimm_size'};
my $desc = $memory->{'dimm_part_number'};
if ($desc !~ /empty/ && $desc =~ s/^0x//) {
# dimm_part_number is an hex string, convert it to ascii
$desc =~ s/^0x//;
# Trim filling "00" from part number, which causes invalid XML down the line.
$desc =~ s/00//g;
$desc = pack "H*", $desc;
$desc =~ s/\s+$//;
# New macs might have some specific characters, perform a regex to fix it
$desc =~ s/(?!-)[[:punct:]]//g;
}
# if system_profiler lables the size in gigs, we need to trim it down to megs so it's displayed properly
if($size =~ /GB$/){
$size =~ s/GB$//;
$size *= 1024;
}
$common->addMemory({
'CAPACITY' => $size,
'SPEED' => $memory->{'dimm_speed'},
'TYPE' => $memory->{'dimm_type'},
'SERIALNUMBER' => $memory->{'dimm_serial_number'},
'DESCRIPTION' => $desc,
'NUMSLOTS' => $slot,
'CAPTION' => 'Status: '.$memory->{'dimm_status'},
});
}
# Send total memory size to inventory object
my $sysctl_memsize=`sysctl -n hw.memsize`;
$common->setHardware({
MEMORY => $sysctl_memsize / 1024 / 1024,
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/Networks.pm 0000664 0000000 0000000 00000011327 14323200667 0024775 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::Networks;
# I think I hijacked most of this from the BSD/Linux modules
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("ifconfig") && $common->can_load("Net::IP qw(:PROC)")
}
sub _ipdhcp {
my $if = shift;
my $path;
my $ipdhcp;
my $leasepath;
foreach ( # XXX BSD paths
"/var/db/dhclient.leases.%s",
"/var/db/dhclient.leases",
# Linux path for some kFreeBSD based GNU system
"/var/lib/dhcp3/dhclient.%s.leases",
"/var/lib/dhcp3/dhclient.%s.leases",
"/var/lib/dhcp/dhclient.leases") {
$leasepath = sprintf($_,$if);
last if (-e $leasepath);
}
return undef unless -e $leasepath;
if (open DHCP, $leasepath) {
my $lease;
my $dhcp;
my $expire;
# find the last lease for the interface with its expire date
while(){
$lease = 1 if(/lease\s*{/i);
$lease = 0 if(/^\s*}\s*$/);
if ($lease) { #inside a lease section
if(/interface\s+"(.+?)"\s*/){
$dhcp = ($1 =~ /^$if$/);
}
#Server IP
if(/option\s+dhcp-server-identifier\s+(\d{1,3}(?:\.\d{1,3}){3})\s*;/
and $dhcp){
$ipdhcp = $1;
}
if (/^\s*expire\s*\d\s*(\d*)\/(\d*)\/(\d*)\s*(\d*):(\d*):(\d*)/
and $dhcp) {
$expire=sprintf "%04d%02d%02d%02d%02d%02d",$1,$2,$3,$4,$5,$6;
}
}
}
close DHCP or warn;
chomp (my $currenttime = `date +"%Y%m%d%H%M%S"`);
undef $ipdhcp unless $currenttime <= $expire;
} else {
warn "Can't open $leasepath\n";
}
return $ipdhcp;
}
# Initialise the distro entry
sub run {
my $params = shift;
my $common = $params->{common};
my $description;
my $ipaddress;
my $ipgateway;
my $ipmask;
my $ipsubnet;
my $macaddr;
my $status;
my $type;
my $speed;
# Looking for the gateway
# 'route show' doesn't work on FreeBSD so we use netstat
# XXX IPV4 only
for(`netstat -nr -f inet`){
$ipgateway=$1 if /^default\s+(\S+)/i;
}
my @ifconfig = `ifconfig -a`; # -a option required on *BSD
# first make the list available interfaces
# too bad there's no -l option on OpenBSD
my @list;
foreach (@ifconfig){
# skip loopback, pseudo-devices and point-to-point interfaces
#next if /^(lo|fwe|vmnet|sit|pflog|pfsync|enc|strip|plip|sl|ppp)\d+/;
next unless(/^en([0-9])/); # darwin has a lot of interfaces, for this purpose we only want to deal with eth0 and eth1
if (/^(\S+):/) { push @list , $1; } # new interface name
}
# for each interface get it's parameters
foreach $description (@list) {
$ipaddress = $ipmask = $macaddr = $status = $type = undef;
# search interface infos
@ifconfig = `ifconfig $description`;
foreach (@ifconfig){
$ipaddress = $1 if /inet (\S+)/i;
$ipmask = $1 if /netmask\s+(\S+)/i;
$macaddr = $2 if /(address:|ether|lladdr)\s+(\S+)/i;
$status = 1 if /status:\s+active/i;
$type = $1 if /media:\s+(\S+)/i;
$speed = $1 if /media:\s+(\S+)\s+(\S+)/i && ! /supported media:/;
if ($speed =~ /autoselect/i) {
$speed = $2 if /media:\s+(\S+)\s+(\S+)/i && ! /supported media:/;
$speed .= " $3" if /media:\s+(\S+)\s+(\S+)\s+(\S+)/i && ! /supported media:/;
} else {
$speed .= " $2" if /media:\s+(\S+)\s+(\S+)/i && ! /supported media:/;
}
}
if ($status != 1) {
$speed = "";
} else {
$speed =~ s/\(|\)|\<|\>|baseTX|baseT|,flow-control//g;
$speed =~ s/1000 /1 Gb\/s /g;
$speed =~ s/100 /100 Mb\/s /g;
$speed =~ s/10 /10 Mb\/s /g;
$speed =~ s/full-duplex/FDX/g;
$speed =~ s/half-duplex/HDX/g;
}
my $binip = &ip_iptobin ($ipaddress ,4);
# In BSD, netmask is given in hex form
my $binmask = sprintf("%b", oct($ipmask));
my $binsubnet = $binip & $binmask;
$ipsubnet = ip_bintoip($binsubnet,4);
my $mask = ip_bintoip($binmask,4);
$common->addNetwork({
DESCRIPTION => $description,
IPADDRESS => ($status?$ipaddress:undef),
IPDHCP => _ipdhcp($description),
IPGATEWAY => ($status?$ipgateway:undef),
IPMASK => ($status?$mask:undef),
IPSUBNET => ($status?$ipsubnet:undef),
MACADDR => $macaddr,
STATUS => ($status?"Up":"Down"),
TYPE => ($status?$type:undef),
SPEED => $speed,
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/Packages.pm 0000664 0000000 0000000 00000003664 14323200667 0024704 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::Packages;
use strict;
use warnings;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_load("Mac::SysProfile");
# Do not run an package inventory if there is the --nosoftware parameter
return if ($params->{config}->{nosoftware});
1;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $profile = Mac::SysProfile->new();
my $data = $profile->gettype('SPApplicationsDataType'); # might need to check version of darwin
return unless($data && ref($data) eq 'ARRAY');
# for each app, normalize the information, then add it to the inventory stack
foreach my $app (@$data){
#my $a = $apps->{$app};
my $path = $app->{'path'} ? $app->{'path'} : 'unknown';
#Exlude from /System/Library/xxx : you can save 150 entries
if ($path =~ /^\/System\/Library\//) {next;}
if ($path =~ /\/System\/Library\// and $path =~ /^\/Volumes\//) {next;}
#Exlude from xxx/Library/Printers/xxx : you can save 10 entries because a printer is an app
if ($path =~ /\/Library\/Printers\//) {next;}
my $kind = $app->{'runtime_environment'} ? $app->{'runtime_environment'} : 'UNKNOWN';
my $store = $app->{'app_store'} ? $app->{'app_store'} : 'no';
my $comments = 'AppStore: '.$store.' - Type: '.$kind.' ';
my $bits = $app->{'has64BitIntelCode'} ? $app->{'has64BitIntelCode'} : 'unknown';
if ($bits eq 'yes') {$bits = '64';} else {$bits = '32';}
$common->addSoftware({
'NAME' => $app->{'_name'},
'VERSION' => $app->{'version'} || 'unknown',
'COMMENTS' => $comments,
'PUBLISHER' => $app->{'info'} || 'unknown',
'INSTALLDATE' => $app->{'lastModified'},
'FOLDER' => $path,
'BITSWIDTH' => $bits,
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/Printers.pm 0000664 0000000 0000000 00000003472 14323200667 0024771 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::Printers;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return(undef) unless -r '/usr/sbin/system_profiler';
return(undef) unless $common->can_load("Mac::SysProfile");
return 1;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $profile = Mac::SysProfile->new();
my $data = $profile->gettype('SPPrintersDataType');
return(undef) unless(ref($data) eq 'ARRAY');
my $status = "";
my $description = "";
my $shared = "";
my @shared = "";
my $oslevel = `sw_vers -productVersion`;
if ($oslevel =~ /10\.[3-6]\./) {
$shared = `awk \'/Info / {gsub("Info ",""); printf \$0">"}; /Shared/ {print \$NF}\' /etc/cups/printers.conf 2>/dev/null | grep -i yes`;
@shared = split(/\n/,$shared);
}
foreach my $printer (@$data){
next if ($printer->{'_name'} =~ /^The\sprinters\slist\sis\sempty\.(.*)$/);
$description = "Status: $printer->{'status'}";
next if ($description =~ /^Status:\s$/);
next if ($description =~ /^Status:\sno_info_found$/);
if ($printer->{'default'} eq "Yes") { $description .= " - Default printer"; }
if ($oslevel =~ /10\.[3-6]\./) {
foreach my $printShared (@shared) {
my ($thisPrinter,$isShared) = split(/>/,$printShared);
if ($printer->{'_name'} eq $thisPrinter) { $description .= " - Shared: yes"; }
}
} else {
if ($printer->{'shared'} eq "Yes") { $description .= " - Shared: yes"; }
}
$common->addPrinter({
NAME => $printer->{'_name'},
DRIVER => $printer->{'ppd'},
PORT => $printer->{'uri'},
DESCRIPTION => $description,
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/Slots.pm 0000664 0000000 0000000 00000002005 14323200667 0024256 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::Slots;
sub check {
my $params = shift;
my $common = $params->{common};
return(undef) unless -r '/usr/sbin/system_profiler'; # check perms
return (undef) unless $common->can_load("Mac::SysProfile");
return 1;
}
sub run {
my $params = shift;
my $common = $params->{common};
my ($name, $description, $status);
# create the profile object and return undef unless we get something back
my $pro = Mac::SysProfile->new();
my $data = $pro->gettype('SPPCIDataType');
return(undef) unless(ref($data) eq 'ARRAY');
foreach my $slot (@$data) {
$name = $slot->{'_name'};
$description = $slot->{'sppci_link-width'}." ".$slot->{'sppci_bus'}." ".$slot->{'sppci_slot_name'};
$common->addSlot({
NAME => $name,
DESCRIPTION => $description,
});
$name = $description = $status = undef;
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/Sound.pm 0000664 0000000 0000000 00000001175 14323200667 0024251 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::Sound;
use strict;
sub check {
return(undef) unless -r '/usr/sbin/system_profiler'; # check perms
return 1;
}
sub run {
my $params = shift;
my $common = $params->{common};
# create profiler obj, bail if datatype fails
my $data = $common->get_sysprofile_devices_names('SPAudioDataType');
return(undef) unless(ref($data) eq 'ARRAY');
# add sound cards
foreach my $sound (@$data){
$common->addSound({
'NAME' => $sound,
'MANUFACTURER' => $sound,
'DESCRIPTION' => $sound,
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/Storages.pm 0000664 0000000 0000000 00000014651 14323200667 0024753 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::Storages;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return $common->can_load('Mac::SysProfile');
return $common->can_run('system_profiler');
}
sub getManufacturer {
my $model = shift;
$model =~ s/APPLE HDD //;
if ($model =~ /(maxtor|western|sony|compaq|hewlett packard|ibm|seagate|toshiba|fujitsu|lg|samsung|nec|transcend|matshita|pioneer|hitachi)/i) {
return ucfirst(lc($1));
} elsif ($model =~ /^APPLE SSD/) {
return "Apple";
} elsif ($model =~ /^HP/) {
return "Hewlett Packard";
} elsif ($model =~ /^WDC/) {
return "Western Digital";
} elsif ($model =~ /^ST/) {
return "Seagate";
} elsif ($model =~ /^HDi|^HT/ or $model =~ /^IC/ or $model =~ /^HU/) {
return "Hitachi";
}
}
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my $devices = {};
my $profile = Mac::SysProfile->new();
# Get SATA Drives
my $sata = $profile->gettype('SPSerialATADataType');
if ( ref($sata) eq 'ARRAY') {
foreach my $storage ( @$sata ) {
next unless ( ref($storage) eq 'HASH' );
my $type;
if ( $storage->{'_name'} =~ /DVD/i || $storage->{'_name'} =~ /CD/i ) {
$type = 'CD-ROM Drive';
} elsif ($storage->{'_name'} =~ /SSD/i || $storage->{'spsata_medium_type'} =~ /Solid State/i) {
$type = 'Disk SSD drive';
}else {
$type = 'Disk drive';
}
my $size = $storage->{'size'};
if ($size =~ /GB/) {
$size =~ s/ GB//;
$size *= 1024;
}
if ($size =~ /TB/) {
$size =~ s/ TB//;
$size *= 1048576;
}
my $manufacturer = getManufacturer($storage->{'_name'});
my $model = $storage->{'device_model'};
$model =~ s/\s*$manufacturer\s*//i;
my $description = "Status: $storage->{'smart_status'}";
if ($storage->{'spsata_trim_support'} =~ /Yes/ ) { $description .= " - Trim: $storage->{'spsata_trim_support'}";}
$devices->{$storage->{'_name'}} = {
NAME => $storage->{'bsd_name'},
SERIALNUMBER => $storage->{'device_serial'},
DISKSIZE => $size,
FIRMWARE => $storage->{'device_revision'},
MANUFACTURER => $manufacturer,
DESCRIPTION => $description,
TYPE => $type,
MODEL => $model
};
}
}
# Get PATA Drives
my $scsi = $profile->gettype('SPParallelSCSIDataType');
if ( ref($scsi) eq 'ARRAY') {
foreach my $storage ( @$scsi ) {
next unless ( ref($storage) eq 'HASH' );
my $type;
if ( $storage->{'_name'} =~ /DVD/i || $storage->{'_name'} =~ /CD/i ) {
$type = 'CD-ROM Drive';
}
else {
$type = 'Disk drive';
}
my $size = $storage->{'size'};
if ($size =~ /GB/) {
$size =~ s/ GB//;
$size *= 1024;
}
if ($size =~ /TB/) {
$size =~ s/ TB//;
$size *= 1048576;
}
my $manufacturer = getManufacturer($storage->{'_name'});
my $model = $storage->{'device_model'};
$model =~ s/\s*$manufacturer\s*//i;
my $description = "Status: $storage->{'smart_status'}";
if ($storage->{'spsata_trim_support'} =~ /Yes/ ) { $description .= " - Trim: $storage->{'spsata_trim_support'}";}
$devices->{$storage->{'_name'}} = {
NAME => $storage->{'_name'},
SERIAL => $storage->{'device_serial'},
DISKSIZE => $size,
FIRMWARE => $storage->{'device_revision'},
MANUFACTURER => $manufacturer,
DESCRIPTION => $description,
MODEL => $model
};
}
}
# Get PATA drives
my $pata = $profile->gettype('SPParallelATADataType');
if ( ref($pata) eq 'ARRAY') {
foreach my $storage ( @$pata ) {
next unless ( ref($storage) eq 'HASH' );
my $type;
if ( $storage->{'_name'} =~ /DVD/i || $storage->{'_name'} =~ /CD/i ) {
$type = 'CD-ROM Drive';
} else {
$type = 'Disk drive';
}
my $manufacturer = getManufacturer($storage->{'_name'});
my $model = $storage->{'device_model'};
my $size = $storage->{'size'};
if ($size =~ /GB/) {
$size =~ s/ GB//;
$size *= 1024;
}
if ($size =~ /TB/) {
$size =~ s/ TB//;
$size *= 1048576;
}
my $description = "";
$devices->{$storage->{'_name'}} = {
NAME => $storage->{'bsd_name'},
SERIALNUMBER=> $storage->{'device_serial'},
DISKSIZE => $size,
FIRMWARE => $storage->{'device_revision'},
MANUFACTURER => $manufacturer,
DESCRIPTION => $description,
TYPE => $type,
MODEL => $model
};
}
}
# Get NVMe Drives
my $nve = $profile->gettype('SPNVMeDataType');
if ( ref($nve) eq 'ARRAY') {
foreach my $storage ( @$nve ) {
next unless ( ref($storage) eq 'HASH' );
my $type = 'Disk NVMe Drive';
my $size = $storage->{'size'};
if ($size =~ /GB/) {
$size =~ s/ GB//;
$size *= 1024;
}
if ($size =~ /TB/) {
$size =~ s/ TB//;
$size *= 1048576;
}
my $manufacturer = getManufacturer($storage->{'_name'});
my $model = $storage->{'device_model'};
$model =~ s/\s*$manufacturer\s*//i;
my $description = "";
$devices->{$storage->{'_name'}} = {
NAME => $storage->{'bsd_name'},
SERIALNUMBER=> $storage->{'device_serial'},
DISKSIZE => $size,
FIRMWARE => $storage->{'device_revision'},
MANUFACTURER => $manufacturer,
DESCRIPTION => $description,
TYPE => $type,
MODEL => $model
};
}
}
foreach my $device ( keys %$devices ) {
$common->addStorages($devices->{$device});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/UUID.pm 0000664 0000000 0000000 00000001057 14323200667 0023726 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::UUID;
use strict;
use warnings;
sub check {
my $params = shift;
my $common = $params->{common};
return(undef) unless -r '/usr/sbin/system_profiler';
return 1;
}
sub run {
my $params = shift;
my $common = $params->{common};
my @sphardware=`system_profiler SPHardwareDataType`;
my $uuid;
foreach my $line (@sphardware){
chomp $line;
$uuid = $1 if ($line =~ /Hardware UUID:\s(.*)/i);
}
$common->setHardware({
UUID => $uuid,
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/Uptime.pm 0000664 0000000 0000000 00000001550 14323200667 0024421 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::Uptime;
use strict;
sub check {
my $boottime = `sysctl -n kern.boottime 2>/dev/null`; # straight from the BSD module ;-)
return 1 if $boottime;
return;
}
sub run {
my $params = shift;
my $common = $params->{common};
# stolen code from bsd.
chomp (my $boottime = `sysctl -n kern.boottime`);
$boottime = $1 if $boottime =~ /sec\s*=\s*(\d+)/;
chomp (my $currenttime = `date +%s`);
my $uptime = $currenttime - $boottime;
# Uptime conversion
my ($UYEAR, $UMONTH , $UDAY, $UHOUR, $UMIN, $USEC) = (gmtime ($uptime))[5,4,3,2,1,0];
# Write in ISO format
$uptime=sprintf "%02d-%02d-%02d %02d:%02d:%02d", ($UYEAR-70), $UMONTH, ($UDAY-1), $UHOUR, $UMIN, $USEC;
chomp(my $DeviceType =`uname -m`);
$common->setHardware({ DESCRIPTION => "$DeviceType/$uptime" });
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/MacOS/Video.pm 0000664 0000000 0000000 00000005015 14323200667 0024224 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::MacOS::Video;
use strict;
use Parse::EDID qw(parse_edid);
sub check {
my $params = shift;
my $common = $params->{common};
# make sure the user has access, cause that's the command that's gonna be run
return(undef) unless -r '/usr/sbin/ioreg';
return(undef) unless -r '/usr/sbin/system_profiler';
return(undef) unless $common->can_load("Mac::SysProfile");
return 1;
}
sub run {
my $params = shift;
my $common = $params->{common};
# run the profiler to get our datatype
my $profile = Mac::SysProfile->new();
my $data = $profile->gettype('SPDisplaysDataType');
# unless we get a valid return, bail out
return(undef) unless(ref($data) eq 'ARRAY');
# we get video card because system_profiler XML output does not provide a human readable value
my $video_names = $common->get_sysprofile_devices_names('SPDisplaysDataType');
return(undef) unless(ref($video_names) eq 'ARRAY');
my $count = 0;
#Getting monitor serial number
#TODO: get serial for multiples monitors
my $ioreg_binary = `ioreg -lw0 | grep "EDID" | sed "/[^<]*{'monitor_name'};
my $ioreg_name = $ioreg->{'serial_number2'};
# add the video information
foreach my $video (@$data){
my $memory;
# macOS 10.13 doesn't have spdisplays_vram but has _spdisplays_vram
if (exists($video->{'spdisplays_vram'})) {
$memory = $video->{'spdisplays_vram'};
} elsif (exists($video->{'_spdisplays_vram'})) {
$memory = $video->{'_spdisplays_vram'};
}
$memory =~ s/ MB$//;
$common->addVideo({
'NAME' => $$video_names[$count],
'CHIPSET' => $video->{'sppci_model'},
'MEMORY' => $memory,
'RESOLUTION' => $video->{'spdisplays_ndrvs'}[0]->{'spdisplays_resolution'},
});
foreach my $display (@{$video->{'spdisplays_ndrvs'}}){
my $serial;
next unless(ref($display) eq 'HASH');
next if($display->{'_name'} eq 'spdisplays_display_connector');
$serial = $ioreg_serial if ($ioreg_name eq $display->{'_name'});
$common->addMonitor({
'CAPTION' => $display->{'_name'},
'SERIAL' => $serial,
})
}
$count++;
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Solaris.pm 0000664 0000000 0000000 00000002164 14323200667 0023632 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Solaris;
use strict;
use vars qw($runAfter);
$runAfter = ["Ocsinventory::Agent::Backend::OS::Generic"];
sub check {$^O =~ /^solaris$/}
sub run {
my $params = shift;
my $common = $params->{common};
my $OSName;
my $OSComment;
my $OSVersion;
my $OSLevel;
my $HWDescription;
my ( $karch, $hostid, $proct, $platform);
#Operating system informations
chomp($OSName=`uname -s`);
chomp($OSLevel=`uname -r`);
chomp($OSComment=`uname -v`);
open(FH, "< /etc/release") and do {
chomp($OSVersion = readline (FH));
$OSVersion =~ s/^\s+//;
close FH;
};
chomp($OSVersion=`uname -v`) unless $OSVersion;
chomp($OSVersion);
$OSVersion=~s/^\s*//;
$OSVersion=~s/\s*$//;
# Hardware informations
chomp($karch=`arch -k`);
chomp($hostid=`hostid`);
chomp($proct=`uname -p`);
chomp($platform=`uname -i`);
$HWDescription = "$platform($karch)/$proct HostID=$hostid";
$common->setHardware({
OSNAME => "$OSName $OSLevel",
OSCOMMENTS => $OSComment,
OSVERSION => $OSVersion,
DESCRIPTION => $HWDescription
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Solaris/ 0000775 0000000 0000000 00000000000 14323200667 0023271 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Solaris/Bios.pm 0000664 0000000 0000000 00000014135 14323200667 0024527 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Solaris::Bios;
# SPARC
# $ showrev
#Hostname: 157501s021plc
#Hostid: 83249bbf
#Release: 5.10
#Kernel architecture: sun4u
#Application architecture: sparc
#Hardware provider: Sun_Microsystems
#Domain: be.cnamts.fr
#Kernel version: SunOS 5.10 Generic_118833-17
#
# $ prtconf -pv (-b would be great...but doesn't work before S10)
#System Configuration: Sun Microsystems sun4u
#Memory size: 16384 Megabytes
#System Peripherals (PROM Nodes):
#
#Node 0xf0819f00
# scsi-initiator-id: 00000007
# node#: 00000000
# #size-cells: 00000002
# stick-frequency: 00bebc20
# clock-frequency: 08f0d180
# idprom: 01840014.4f4162cb.45255cf4.4162cb16.55555555.55555555.55555555.55555555
# breakpoint-trap: 0000007f
# device_type: 'gptwo'
# banner-name: 'Sun Fire E6900'
# compatible: 'SUNW,Serengeti'
# newio-addr: 00000001
# name: 'SUNW,Sun-Fire'
# X64
# $ showrev
#Hostname: stlaurent
#Hostid: 403100b
#Release: 5.10
#Kernel architecture: i86pc
#Application architecture: i386
#Hardware provider:
#Domain:
#Kernel version: SunOS 5.10 Generic_127112-07
#
# $ smbios -t SMB_TYPE_SYSTEM
#ID SIZE TYPE
#1 76 SMB_TYPE_SYSTEM (system information)
#
# Manufacturer: Sun Microsystems, Inc.
# Product: Sun Fire V40z
# Version: 00
# Serial Number: R00T34E0009
#
# UUID: be1630df-d130-41a4-be32-fd28bb4bd1ac
# Wake-Up Event: 0x6 (power switch)
# SKU Number:
# Family:
use strict;
sub run {
my $params = shift;
my $common = $params->{common};
my $zone;
my( $SystemSerial , $SystemModel, $SystemManufacturer, $ChassisType, $MotherBoardSerial, $MotherBoardModel, $MotherBoardManufacturer, $BiosManufacturer, $BiosVersion, $BiosDate, $aarch);
if ( !$common->can_run("zonename") || `zonename` =~ /global/ ) {
# Ether pre Sol10 or in Sol10/Sol11 global zone
$zone = "global";
} else {
$zone = "";
}
if ($zone){
chomp($SystemModel = `uname -m`);
chomp($aarch = `uname -p`);
if( $aarch eq "i386" ){
#
# For a Intel/AMD arch, we're using smbios
#
foreach(`/usr/sbin/smbios -t SMB_TYPE_SYSTEM`) {
if(/^\s*Manufacturer:\s*(.+)$/){$SystemManufacturer = $1};
if(/^\s*Serial Number:\s*(.+)$/){$SystemSerial = $1;}
if(/^\s*Product:\s*(.+)$/){$SystemModel = $1;}
}
foreach(`/usr/sbin/smbios -t SMB_TYPE_BIOS`) {
if(/^\s*Vendor:\s*(.+)$/){$BiosManufacturer = $1};
if(/^\s*Version String:\s*(.+)$/){$BiosVersion = $1};
if(/^\s*Release Date:\s*(.+)$/){$BiosDate = $1};
}
foreach(`/usr/sbin/smbios -t SMB_TYPE_BASEBOARD`) {
if(/^\s*Product\s*(.+)$/){$MotherBoardModel = $1};
if(/^\s*Serial Number:\s*(.+)$/){$MotherBoardSerial = $1};
if(/^\s*Manufacturer:\s*(.+)$/){$MotherBoardManufacturer = $1};
}
foreach(`/usr/sbin/smbios -t SMB_TYPE_CHASSIS`) {
if(/^\s*Chassis Type:.*\((.+)\)$/) {$ChassisType = $1};
}
} elsif( $aarch eq "sparc" ) {
#
# For a Sparc arch, we're using prtconf
#
my $name;
my $OBPstring;
my $found=0;
if ( $common->can_run("virtinfo") && `virtinfo -t` =~ /.*LDoms guest.*/ ) {
foreach(`virtinfo -a`) {
if(/^Domain role:\s*(.+)$/) {$ChassisType = $1};
if(/^Chassis serial.:\s*(.+)$/) {$SystemSerial = $1};
}
}
foreach(`/usr/sbin/prtconf -pv`) {
# prtconf is an awful thing to parse
if(/^System Configuration:\s*(.+)\s+\S+$/) {$SystemManufacturer = $1; $BiosManufacturer = $1; }
if(/^\s*banner-name:\s*'(.+)'$/){$SystemModel = $1;}
unless ($name)
{ if(/^\s*name:\s*'(.+)'$/){$name = $1;} }
unless ($OBPstring) {
if(/^\s*version:\s*'(.+)'$/){
$OBPstring = $1;
# looks like : "OBP 4.33.6.f 2014/07/10 10:24"
# with further informations sometimes
if( $OBPstring =~ m@OBP\s+(\S+)\s+(\d+)/(\d+)/(\d+)@ ){
$BiosVersion = "OBP $1";
$BiosDate = "$2/$3/$4";
} else { $BiosVersion = $OBPstring }
}
}
}
$SystemModel .= " ($name)" if( $name );
if ( $common->can_run("ipmitool") ) {
foreach(`/usr/sbin/ipmitool fru print`) {
if (/^\s*Chassis Type\s+:\s+(.+)/) {
$ChassisType = $1;
$found = 1;
}
elsif ( $found && /^\s*Product Serial\s+:\s+(.+)/) {
$SystemSerial = $1;
last;
}
}
}
if ( !$SystemSerial ) {
# No serial found via ipmitool, so use sneep
if( -x "/opt/SUNWsneep/bin/sneep" ) {
chomp($SystemSerial = `/opt/SUNWsneep/bin/sneep`);
}else {
foreach(`/bin/find /opt -name sneep`) {
chomp($SystemSerial = `$1`) if /^(\S+)/;
}
if (!$SystemSerial){
$SystemSerial = "Please install package SUNWsneep";
}
}
}
}
}else{
foreach(`showrev`){
if(/^Hardware provider:\s+(\S+)/){$SystemManufacturer = $1};
}
$SystemModel = "Solaris Containers";
$SystemSerial = "Solaris Containers";
}
# Writing data
$common->setBios ({
BVERSION => $BiosVersion,
BDATE => $BiosDate,
BMANUFACTURER => $BiosManufacturer,
SMANUFACTURER => $SystemManufacturer,
SMODEL => $SystemModel,
SSN => $SystemSerial,
MMANUFACTURER => $MotherBoardManufacturer,
MSN => $MotherBoardSerial,
TYPE => $ChassisType,
MMODEL => $MotherBoardModel
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Solaris/CPU.pm 0000664 0000000 0000000 00000003533 14323200667 0024262 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Solaris::CPU;
use strict;
use warnings;
use English qw(-no_match_vars);
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my (%params) = @_;
my $current;
my $cpus=`/usr/bin/kstat -m cpu_info | egrep "chip_id|core_id|module: cpu_info" | grep chip_id | awk '{ print \$2 }' | sort -u | wc -l | tr -d ' '`;
my $ncores=`/usr/bin/kstat -m cpu_info | egrep "chip_id|core_id|module: cpu_info" | grep core_id | awk '{ print \$2 }' | sort -u | wc -l | tr -d ' '`;
my $vproc=`/usr/bin/kstat -m cpu_info | egrep "chip_id|core_id|module: cpu_info" | grep 'module: cpu_info' | awk '{ print \$4 }' | sort -u | wc -l | tr -d ' '`;
my $cores=$ncores / $cpus;
my $threads=$vproc / $cpus;
my $speed=`/usr/bin/kstat -m cpu_info | grep clock_MHz | awk '{ print \$2 }' | sort -u`;
my $type=`/usr/bin/kstat -m cpu_info | grep brand | awk '{\$1=""}; { print \$0 }' | sort -u`;
my $manufacturer =
$type =~ /SPARC/ ? 'SPARC' :
$type =~ /Xeon/ ? 'Intel' :
undef ;
my $cpuarch=`isainfo | tr ' ' '_'`;
$logger->debug("NB CPUs: $cpus");
$logger->debug("CORES: $cores");
$logger->debug("LOGICAL_CPUS: $threads");
$logger->debug("SPEED: $speed");
$logger->debug("TYPE: $type");
$logger->debug("MANUFACTURER: $manufacturer");
$logger->debug("CPUARCH: $cpuarch");
for my $i (1 .. $cpus) {
$current->{MANUFACTURER} = $manufacturer if chomp($manufacturer);
$current->{SPEED} = $speed if chomp($speed);
$current->{TYPE} = $type if chomp($type);
$current->{CORES} = $cores if $cores;
$current->{LOGICAL_CPUS} = $threads if $threads;
$current->{CPUARCH} = $cpuarch if chomp($cpuarch);
$common->addCPU($current);
}
}
#run();
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Solaris/Controllers.pm 0000664 0000000 0000000 00000001530 14323200667 0026134 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Solaris::Controllers;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run ("cfgadm")
}
sub run {
my $params = shift;
my $common = $params->{common};
my $name;
my $type;
my $description;
foreach(`cfgadm -s cols=ap_id:type:info`){
$name = $type = $description = "";
next if (/^Ap_Id/);
if (/^(\S+)\s+/){
$name = $1;
}
if(/^\S+\s+(\S+)/){
$type = $1;
}
#No manufacturer, but informations about controller
if(/^\S+\s+\S+\s+(.*)/){
$description = $1;
}
$common->addController({
'NAME' => $name,
'TYPE' => $type,
'DESCRIPTION' => $description,
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Solaris/Domains.pm 0000664 0000000 0000000 00000001345 14323200667 0025224 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Solaris::Domains;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run ("domainname")
}
sub run {
my $params = shift;
my $common = $params->{common};
my $domain;
chomp($domain = `domainname`);
if (!$domain) {
my %domain;
if (open RESOLV, "/etc/resolv.conf") {
while() {
$domain{$2} = 1 if (/^(domain|search)\s+(.+)/);
}
close RESOLV;
}
$domain = join "/", keys %domain;
}
# If no domain name, we send "WORKGROUP"
$domain = 'WORKGROUP' unless $domain;
$common->setHardware({
WORKGROUP => $domain
});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Solaris/Drives.pm 0000664 0000000 0000000 00000003702 14323200667 0025065 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Solaris::Drives;
#Filesystem kbytes used avail capacity Mounted on
#/dev/vx/dsk/bootdg/rootvol 16525754 5423501 10936996 34% /
#/devices 0 0 0 0% /devices
#ctfs 0 0 0 0% /system/contract
#proc 0 0 0 0% /proc
#mnttab 0 0 0 0% /etc/mnttab
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run ("df")
}
sub run {
my $params = shift;
my $common = $params->{common};
my $free;
my $filesystem;
my $total;
my $type;
my $volumn;
#Looking for mount points and disk space
for (`df -k`){
if (/^Filesystem\s*/){next};
# on Solaris 10 and up, /devices is an extra mount which we like to exclude
if (/^\/devices/){next};
# on Solaris 10 and up, /platform/.../libc_psr_hwcap1.so.1 is an extra mount which we like to exclude
if (/^\/platform/){next};
# exclude cdrom mount point
if (/^\/.*\/cdrom/){next};
if (/^swap.*/){next};
# exclude special entries such as ctfs, proc, mnttab, etc...
if (/^.*\s+0\s+0\s+0.*/){next};
# skip nfs (dirty hack)
if (/^\S+:\/.*/){next};
# everything else is a local filesystem
if (/^(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\n/){
$filesystem = $6;
$total = sprintf("%i",($2/1024));
$free = sprintf("%i",($4/1024));
$volumn = $1;
chomp($type = `mount -v | grep " $filesystem "`);
$type =~ s/\S+\s+on\s+\S+\s+type\s+(\S+)\s+.*/$1/;
$common->addDrive({
FREE => $free,
FILESYSTEM => $filesystem,
TOTAL => $total,
TYPE => $type,
VOLUMN => $volumn
});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Solaris/IPv4.pm 0000664 0000000 0000000 00000002202 14323200667 0024405 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Solaris::IPv4;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run ("ifconfig")
}
# Initialise the distro entry
sub run {
my $params = shift;
my $common = $params->{common};
my %ip;
my $ip;
my $hostn;
#Looking for ip addresses with ifconfig, except loopback
# Solaris need -a option
for (`ifconfig -a`){#ifconfig in the path
#Solarisligne inet
if (/^\s*inet\s+(\S+).*/){($1=~/^127.+/)?next:($ip{$1}=1)};
}
# Ok. Now, we have the list of IP addresses configured
# We could have too many addresses to list them in HW
# (details will be sent in Networks instead)
#
# How could we choose ?
#
# Let's try to resolve the name of our server
#
chomp( $hostn = `uname -n` );
if ($hostn) {
my $aip;
foreach (`ping -s $hostn 10 1`) {
unless ( $ip ) {
if( /^.*\((\d+\.\d+\.\d+\.\d+)\):.*/ ) {
$aip = $1;
$ip = $aip if( exists($ip{$aip}) );
}
}
}
}
$common->setHardware({IPADDR => $ip});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Solaris/Mem.pm 0000664 0000000 0000000 00000001324 14323200667 0024345 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Solaris::Mem;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run ("swap") && $common->can_run ("prtconf")
}
sub run {
my $params = shift;
my $common = $params->{common};
#my $unit = 1024;
my $PhysicalMemory;
my $SwapFileSize;
# Memory informations
foreach(`prtconf`){
if(/^Memory\ssize:\s+(\S+)/){
#print "total memoire: $1";
$PhysicalMemory = $1};
}
#Swap Informations
foreach(`swap -l`){
if(/\s+(\S+)$/){$SwapFileSize = $1};
}
$common->setHardware({
MEMORY => $PhysicalMemory,
SWAP => $SwapFileSize
});
}
1
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Solaris/Memory.pm 0000664 0000000 0000000 00000054503 14323200667 0025106 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Solaris::Memory;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run ("memconf")
}
sub run {
my $model;
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my $capacity;
my $description;
my $numslots;
my $speed = undef;
my $type = undef;
my $banksize;
my $module_count=0;
my $empty_slots;
my $flag=0;
my $flag_mt=0;
my $caption;
my $sun_class=0;
my $OSLevel;
my $zone;
my $aarch;
# for debug only
my $j=0;
# first, we need determinate on which model of sun server we run,
# because prtdiags output (and with that memconfs output) is differend
# from server model to server model
# we try to classified our box in one of the known classes
chomp($OSLevel = `uname -r`);
chomp($aarch = `uname -p`);
if ( !$common->can_run("zonename") || `zonename` =~ /global/ ) {
# Either pre Sol10 or in Sol10/Sol11 global zone
$zone = "global";
}else{
# Sol10/Sol11 local zone
$zone = "";
}
#print "Nom :".$zone."*************************\n";
if ($zone)
{
if ( $aarch =~ /sparc/ && $common->can_run("virtinfo") && `virtinfo -t` =~ /.*LDoms guest.*/ ) {
$model = "Solaris Ldom";
}else{
chomp($model = `uname -i`);
}
}else{
$model="Solaris Containers";
}
#print "Memory Model: $model\n";
#$model=`uname -i`;
# debug print model
#print "Model: '$model'";
# cut the CR from string model
#$model = substr($model, 0, length($model)-1);
# we map (hopfully) our server model to a known class
#if ($model eq "SUNW,Sun-Fire-280R") { $sun_class = 1; }
#if ($model eq "SUNW,Sun-Fire-480R") { $sun_class = 1; }
#if ($model eq "SUNW,Sun-Fire-V490") { $sun_class = 1; }
#if ($model eq "SUNW,Sun-Fire-880") { $sun_class = 1; }
#if ($model eq "SUNW,Sun-Fire-V240") { $sun_class = 2; }
#if ($model eq "SUNW,Sun-Fire-V440") { $sun_class = 2; }
#if ($model eq "SUNW,Sun-Fire-V250") { $sun_class = 2; }
#if ($model eq "SUNW,Sun-Fire-T200") { $sun_class = 3; }
#if ($model eq "SUNW,Sun-Fire-T1000") { $sun_class = 3; }
#if ($model eq "SUNW,SPARC-Enterprise-T5220") { $sun_class = 4; }
#if ($model eq "SUNW,SPARC-Enterprise") { $sun_class = 5; } # for M5000 && M4000
if ($model =~ /SUNW,SPARC-Enterprise/) { $sun_class = 5; } # for M5000 && M4000
if ($model =~ /SUNW,SPARC-Enterprise-T\d/){ $sun_class = 4; }
if ($model =~ /SUNW,Netra-T/){ $sun_class = 2; }
if ($model =~ /SUNW,Sun-Fire-\d/){ $sun_class = 1; }
if ($model =~ /SUNW,Sun-Fire-V/){ $sun_class = 2; }
if ($model =~ /SUNW,Sun-Fire-V490/) { $sun_class = 1; }
if ($model =~ /SUNW,Sun-Fire-T\d/) { $sun_class = 3; }
if ($model =~ /SUNW,SPARCstation/) { $sun_class = 3; }
if ($model =~ /SUNW,Ultra-/) { $sun_class = 3; }
if ($model =~ /SUNW,Sun-Blade-100/) { $sun_class = 8; }
if ($model =~ /SUNW,Sun-Blade-1500/) { $sun_class = 8; }
if ($model =~ /SUNW,T\d/) { $sun_class = 3; }
if ($model =~ /Solaris Containers/){ $sun_class = 7; }
if ($model =~ /Solaris Ldom/) { $sun_class = 7; }
if ($model =~ /i86pc/) { $sun_class = 6; }
if ($model =~ /sun4v/) { $sun_class = 3; }
# debug print model
#print "Sunclass: $sun_class\n";
# now we can look at memory information, depending from our class
if($sun_class == 0)
{
$logger->debug("sorry, unknown model, could not detect memory configuration");
}
if($sun_class == 1)
{
foreach(`memconf 2>&1`)
{
# debug
#print "count: " .$j++ . " " . $flag_mt . " : " . "$_";
# if we find "empty groups:", we have reached the end and indicate that by setting flag = 0
if(/^empty \w+:\s(\S+)/)
{
$flag = 0;
if($1 eq "None"){$empty_slots = 0;}
}
# grep the type of memory modules from heading
if($flag_mt && /^\s*\S+\s+\S+\s+\S+\s+\S+\s+(\S+)/) {$flag_mt=0; $description = $1;}
# only grap for information if flag = 1
if ($flag && /^\s*(\S+)\s+(\S+)/) { $caption = "Board " . $1 . " MemCtl " . $2; }
if ($flag && /^\s*\S+\s+\S+\s+(\S+)/) { $numslots = $1; }
if ($flag && /^\s*\S+\s+\S+\s+\S+\s+(\d+)/) { $banksize = $1; }
if ($flag && /^\s*\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\d+)/) { $capacity = $1; }
if ($flag)
{
for (my $i = 1; $i <= ($banksize / $capacity); $i++)
{
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n";
$module_count++;
$common->addMemory({
CAPACITY => $capacity,
DESCRIPTION => $description,
CAPTION => $caption,
SPEED => $speed,
TYPE => $type,
NUMSLOTS => $numslots
})
}
}
# this is the caption line
if(/^\s+Logical Logical Logical/) { $flag_mt = 1; }
# if we find "---", we set flag = 1, and in next line, we start to look for information
if(/^-+/){ $flag = 1; }
}
#print "# of RAM Modules: " . $module_count . "\n";
#print "# of empty slots: " . $empty_slots . "\n";
}
if($sun_class == 2)
{
foreach(`memconf 2>&1`)
{
# debug
#print "line: " .$j++ . " " . $flag_mt . "/" . $flag ." : " . "$_";
# if we find "empty sockets:", we have reached the end and indicate that by resetting flag = 0
# emtpy sockets is follow by a list of emtpy slots, where we extract the slot names
if(/^empty sockets:\s*(\S+)/)
{
$flag = 0;
# cut of first 15 char containing the string empty sockets:
substr ($_,0,15) = "";
$capacity = "empty";
$numslots = 0;
foreach $caption (split)
{
if ($caption eq "None")
{
$empty_slots = 0;
# no empty slots -> exit loop
last;
}
# debug
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n";
$empty_slots++;
$common->addMemory({
CAPACITY => $capacity,
DESCRIPTION => $description,
CAPTION => $caption,
SPEED => $speed,
TYPE => $type,
NUMSLOTS => $numslots
})
}
}
if(/.*Memory Module Groups.*/)
{
$flag = 0;
$flag_mt = 0;
}
# we only grap for information if flag = 1
if($flag && /^\s*\S+\s+\S+\s+(\S+)/){ $caption = $1; }
if($flag && /^\s*(\S+)/){ $numslots = $1; }
if($flag && /^\s*\S+\s+\S+\s+\S+\s+(\d+)/){ $capacity = $1; }
if($flag)
{
# debug
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n";
$module_count++;
$common->addMemory({
CAPACITY => $capacity,
DESCRIPTION => "DIMM",
CAPTION => "Ram slot ".$numslots,
SPEED => $speed,
TYPE => $type,
NUMSLOTS => $numslots
})
}
# this is the caption line
if(/^ID ControllerID/) { $flag_mt = 1; $description = $1;}
# if we find "---", we set flag = 1, and in next line, we start to look for information
if($flag_mt && /^-+/){ $flag = 1;}
}
# debug: show number of modules found and number of empty slots
}
if($sun_class == 3)
{
# socket MB/MEM3/CMP3/BR1/CH1/D2 has a Micron Technology 36HTF51272F80EE1D4 4GB FB-DIMM
foreach(`memconf 2>&1`)
{
# debug
if(/^empty sockets:\s*(\S+)/)
{
# cut of first 15 char containing the string empty sockets:
substr ($_,0,15) = "";
$description = "";
$type = "";
$capacity = "empty";
$numslots = 0;
foreach $caption (split)
{
if ($caption eq "None")
{
$empty_slots = 0;
# no empty slots -> exit loop
last;
}
# debug
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n";
$empty_slots++;
$common->addMemory({
CAPACITY => $capacity,
DESCRIPTION => $description,
CAPTION => $caption,
SPEED => $speed,
TYPE => $type,
NUMSLOTS => $numslots
})
}
}
# socket MB/MEM3/CMP3/BR1/CH1/D2 has a Micron Technology 36HTF51272F80EE1D4 4GB FB-DIMM
if(/^socket\s+(\S+) has a (.+) (\d+)GB (\S+)/)
{
$caption = $1;
$description = $2;
$type = $4;
$numslots = 0;
$capacity = $3 * 1024;
# debug
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n";
$module_count++;
$common->addMemory({
CAPACITY => $capacity,
DESCRIPTION => $description,
CAPTION => $caption,
SPEED => $speed,
TYPE => $type,
NUMSLOTS => $numslots
})
}
# socket P1C1/B31/C1/D0 (LUN 0 ID 124): Samsung 32768MB DDR4 SDRAM DIMM, M393A4K40BB1-CRC
if(/^socket\s+(\S+) \(LUN \d+ ID \d+\): (.+) (\d+)MB (\S+) (\S+) DIMM, (\S+)/)
{
$caption = $1;
$description = "$2 $6";
$type = "$4 $5";
$numslots = 0;
$capacity = $3;
$module_count++;
$common->addMemory({
CAPACITY => $capacity,
DESCRIPTION => $description,
CAPTION => $caption,
SPEED => $speed,
TYPE => $type,
NUMSLOTS => $numslots
})
}
}
# debug: show number of modules found and number of empty slots
#print "# of RAM Modules: " . $module_count . "\n";
#print "# of empty slots: " . $empty_slots . "\n";
}
if($sun_class == 4)
{
foreach(`memconf 2>&1`)
{
# debug
#print "line: " .$j++ . " " . $flag_mt . "/" . $flag ." : " . "$_";
# if we find "empty sockets:", we have reached the end and indicate that by resetting flag = 0
# emtpy sockets is follow by a list of emtpy slots, where we extract the slot names
if(/^empty sockets:\s*(\S+)/)
{
$flag = 0;
# cut of first 15 char containing the string empty sockets:
substr ($_,0,15) = "";
$capacity = "empty";
$numslots = 0;
foreach $caption (split)
{
if ($caption eq "None")
{
$empty_slots = 0;
# no empty slots -> exit loop
last;
}
# debug
print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n";
$empty_slots++;
$common->addMemory({
CAPACITY => $capacity,
DESCRIPTION => $description,
CAPTION => $caption,
SPEED => $speed,
TYPE => $type,
NUMSLOTS => $numslots
})
}
}
# we only grap for information if flag = 1
# socket MB/CMP0/BR0/CH0/D0 has a Samsung 501-7953-01 Rev 05 2GB FB-DIMM
if(/^socket\s+(\S+) has a (.+)\s+(\S+)GB\s+(\S+)$/i)
{
$caption = $1;
$description = $2;
$type = $4;
$numslots = 0;
$capacity = $3 * 1024;
# debug
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n";
$module_count++;
$common->addMemory({
CAPACITY => $capacity,
DESCRIPTION => $description,
CAPTION => $caption,
SPEED => $speed,
TYPE => $type,
NUMSLOTS => $numslots
})
}
}
# debug: show number of modules found and number of empty slots
#print "# of RAM Modules: " . $module_count . "\n";
#print "# of empty slots: " . $empty_slots . "\n";
}
if ($sun_class == 5 )
{
foreach(`memconf 2>&1`)
{
# debug
#print "line: " .$j++ . " " . $flag_mt . "/" . $flag ." : " . "$_";
# if we find "empty sockets:", we have reached the end and indicate that by resetting flag = 0
# emtpy sockets is follow by a list of emtpy slots, where we extract the slot names
if(/^total memory.*(\S+)/) { $flag = 0;}
#print "flag : $flag\n";
if($flag_mt && /^\s+\S+\s+\S+\s+\S+\s+(\S+)/) {$flag_mt=0; $type = $1;}
#print "description : $description\n";
if ($flag && /^\s(\S+)\s+(\S+)/) { $numslots = "LSB " . $1 . " Group " . $2; }
if ($flag && /^\s(\S+)\s+(\S+)/) { $caption = "LSB " . $1 . " Group " . $2; }
if ($flag && /^\s+\S+\s+\S\s+\S+\s+\S+\s+(\d+)/) { $capacity = $1; }
if ($flag && /^\s+\S+\s+\S\s+(\d+)/) { $banksize = $1; }
#print "Num slot ". $numslots . " Bank Number: " . $numslots . " Bank size " . $banksize . " DIMM Capacity: " . $capacity . "MB\n";
if ($flag && $capacity > 1 )
{
for (my $i = 1; $i <= ($banksize / $capacity); $i++)
{
#print "caption ". $caption . " Bank Number: " . $numslots . " Bank size " . $banksize . " DIMM Capacity: " . $capacity . "MB\n";
$common->addMemory({
CAPACITY => $capacity,
DESCRIPTION => $description,
CAPTION => $caption,
SPEED => $speed,
TYPE => $type,
NUMSLOTS => $module_count
})
}
$module_count++;
}
#Caption Line
if (/^Sun Microsystems/) { $flag_mt=1; $flag=1; }
}
}
if($sun_class == 6)
{
#CPU1_D2 BANK2: 4096MB DDR3 DIMM, Samsung M393B5170EH1-CH9 (SUN FIRE X4270)
#DIMM 1A: 4096MB Synchronous DDR2 FBDIMM (ProLiant DL380 G5)
#Board 1, DIMM 1A: 8192MB Synchronous DDR3 (ProLiant DL580 G7)
#PROC 1 DIMM 12: 16384MB Synchronous DDR3 DIMM, HP (ProLiant DL380p Gen8)
#PROC 1 DIMM 12: 32768MB Synchronous DIMM, HP 752372-081 (ProLiant DL380 Gen9)
#XMM1: 2048MB Synchronous DDR2 DIMM, Elpida EBE21UE8AEFA-8G-E (HP Desktop PC)
#DIMM_1: 1024MB Synchronous DDR2 DIMM, Kingston KCM633-ELC (Dell Desktop PC)
foreach(`memconf 2>&1`)
{
# debug
#print "line: " .$j++ . " " . $flag_mt . "/" . $flag ." : " . "$_";
if(/^empty memory sockets:\s*(\S+)/)
{
# cut of first 22 char containing the string empty sockets:
substr ($_,0,22) = "";
chomp();
$capacity = "0";
$numslots = 0;
foreach $caption (split(/, /,$_))
{
if ($caption eq "None")
{
$empty_slots = 0;
# no empty slots -> exit loop
last;
}
# debug
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n";
$empty_slots++;
if ($caption =~ /.* (\d+)$/) { $numslots = $1; }
$common->addMemory({
CAPACITY => $capacity,
DESCRIPTION => "empty",
CAPTION => $caption,
SPEED => 'n/a',
TYPE => 'n/a',
NUMSLOTS => $numslots
})
}
}
# These are the non-emtpy sockets in various formats
#DIMM 1A: 4096MB Synchronous DDR2 FBDIMM (ProLiant DL380 G5)
#Board 1, DIMM 1A: 8192MB Synchronous DDR3 (ProLiant DL580 G7)
#PROC 1 DIMM 12: 16384MB Synchronous DDR3 DIMM, HP (ProLiant DL380p Gen8)
if(/^(.*DIMM) (\S+):\s+(\d+)MB\s(\S+ DDR\d+)\s*(\w*)?(,?.*)/)
{
$caption = "$1 $2";
$description = "$4 $5$6";
$numslots = $2;
$capacity = $3;
$type = $5;
unless ($type) { $type = "DIMM" }; # Default if nothing else found
# debug
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n";
$module_count++;
$common->addMemory({
CAPACITY => $capacity,
DESCRIPTION => $description,
CAPTION => $caption,
SPEED => $speed,
TYPE => $type,
NUMSLOTS => $numslots
})
}
#CPU1_D2 BANK2: 4096MB DDR3 DIMM, Samsung M393B5170EH1-CH9 (SUN FIRE X4270)
if(/^(.*BANK)(\S+):\s+(\d+)MB\s(\S*DDR\d+)\s*(\w+)?(,?.*)/)
{
$caption = "$1 $2";
$description = "$4 $5$6";
$numslots = $2;
$capacity = $3;
$type = $5;
# debug
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n";
$module_count++;
$common->addMemory({
CAPACITY => $capacity,
DESCRIPTION => $description,
CAPTION => $caption,
SPEED => $speed,
TYPE => $type,
NUMSLOTS => $numslots
})
}
#PROC 1 DIMM 12: 32768MB Synchronous DIMM, HP 752372-081 (ProLiant DL380 Gen9)
if(/^(.*DIMM) (\S+):\s+(\d+)MB\s(\S+)\s+(DIMM\w*)(,?.*)/)
{
$caption = "$1 $2";
$description = "$4 $5$6";
$numslots = $2;
$capacity = $3;
$type = $5;
# debug
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n";
$module_count++;
$common->addMemory({
CAPACITY => $capacity,
DESCRIPTION => $description,
CAPTION => $caption,
SPEED => $speed,
TYPE => $type,
NUMSLOTS => $numslots
})
}
#XMM1: 2048MB Synchronous DDR2 DIMM, Elpida EBE21UE8AEFA-8G-E (HP Desktop PC)
#DIMM_1: 1024MB Synchronous DDR2 DIMM, Kingston KCM633-ELC (Dell Desktop PC)
if(/^(\S+):\s+(\d+)MB\s(.+)\s+(DIMM\w*)(,?.*)/)
{
$caption = "$1";
$description = "$3 $4$5";
$numslots = $1;
$capacity = $2;
$type = $4;
# debug
#print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n";
$module_count++;
$common->addMemory({
CAPACITY => $capacity,
DESCRIPTION => $description,
CAPTION => $caption,
SPEED => $speed,
TYPE => $type,
NUMSLOTS => $numslots
})
}
}
# debug: show number of modules found and number of empty slots
#print "# of RAM Modules: " . $module_count . "\n";
#print "# of empty slots: " . $empty_slots . "\n";
}
if ($sun_class == 7)
{
foreach (`prctl -n project.max-shm-memory $$ 2>&1`)
{
$description = $1 if /^project.(\S+)$/;
$capacity = $1 if /^\s*system+\s*(\d+).*$/;
if(($description && $capacity)){
$capacity = $capacity * 1024;
$numslots = 1 ;
$description = "Memory Allocated";
$caption = "Memory Share";
#print $description."_".$capacity."***\n";
$common->addMemory({
CAPACITY => $capacity,
DESCRIPTION => $description,
CAPTION => $caption,
SPEED => $speed,
TYPE => $type,
NUMSLOTS => $numslots
})
}
}
}
if($sun_class == 8) {
# example output of a Sun Blade 100 Workstation
#Sun Microsystems, Inc. Sun Blade 100 (UltraSPARC-IIe 502MHz)
#Memory Segment Table:
#-----------------------------------------------------------------------
#Base Address Size Interleave Factor Contains
#-----------------------------------------------------------------------
#0x0 256MB 1 chassis/system-board/DIMM0
#empty sockets: DIMM1 DIMM2 DIMM3
#total memory = 256MB
#Sun Microsystems, Inc. Sun Blade 100 (UltraSPARC-IIe 502MHz)
#Memory Segment Table:
#-----------------------------------------------------------------------
#Base Address Size Interleave Factor Contains
#-----------------------------------------------------------------------
#0x0 256MB 1 Label DIMM0
#0x20000000 256MB 1 Label DIMM1
#empty sockets: DIMM2 DIMM3
#total memory = 512MB
foreach(`memconf 2>&1`) {
if (/^empty sockets:\s*(.+)/) {
foreach $caption (split(/ /, $1)) {
if ($caption eq "None") {
$empty_slots = 0;
last;
}
$empty_slots++;
# print "empty slot\n";
$common->addMemory({
CAPACITY => "empty",
DESCRIPTION => '',
CAPTION => $caption,
SPEED => '',
TYPE => '',
NUMSLOTS => $numslots
})
}
}
if (/^0x(\d+)\s+(\d+)(\S)B\s+(\S+)\s+(.+)/) {
$caption = "$5";
$description = "";
$numslots = 0;
$capacity = $2 if ( $3 eq "M" );
$capacity = $2 * 1024 if ( $3 eq "G" );
$type = "";
# debug
# print "Caption: " . $caption . " Description: " . $description . " Bank Number: " . $numslots . " DIMM Capacity: " . $capacity . "MB\n";
$module_count++;
$common->addMemory({
CAPACITY => $capacity,
DESCRIPTION => $description,
CAPTION => $caption,
SPEED => $speed,
TYPE => $type,
NUMSLOTS => $numslots
})
}
}
}
}
#run();
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Solaris/Networks.pm 0000664 0000000 0000000 00000011314 14323200667 0025443 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Solaris::Networks;
#ce5: flags=1000843 mtu 1500 index 3
# inet 55.37.101.171 netmask fffffc00 broadcast 55.37.103.255
# ether 0:3:ba:24:9b:bf
#aggr40001:2: flags=201000843 mtu 1500 index 3
# inet 55.37.101.172 netmask ffffff00 broadcast 223.0.146.255
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run("ifconfig") && $common->can_run("netstat") && $common->can_load ("Net::IP qw(:PROC)")
}
# Initialise the distro entry
sub run {
my $params = shift;
my $common = $params->{common};
my $description;
my $ipaddress;
my $ipgateway;
my $ipmask;
my $ipsubnet;
my $macaddr;
my $status;
my $type;
my $zone;
my @zoneadmcmd;
my @zacsplitted;
# get the first field of the first line of "zoneadm list -p"
@zoneadmcmd = `zoneadm list -p`;
@zacsplitted = split(/:/, $zoneadmcmd[0]);
$zone = $zacsplitted[0];
foreach (`netstat -rn`){
$ipgateway=$1 if /^default\s+(\S+)/i;
}
#print "Nom :".$zone."*************************\n";
### STEP 1: get aliases and zones' interfaces
foreach (`ifconfig -a`){
# resets if new interface
$ipaddress = $description = $macaddr = $status = $type = undef if /^(\S+):/;
# interface name and other data
$description = $1.":".$2 if /^(\S+):(\S+):/;
$ipaddress = $1 if /inet\s+(\S+)/i;
$ipmask = $1 if /\S*netmask\s+(\S+)/i;
if (/ether\s+(\S+)/i) {
# See
# https://sourceforge.net/tracker/?func=detail&atid=487492&aid=1819948&group_id=58373
$macaddr = sprintf "%02x:%02x:%02x:%02x:%02x:%02x" ,
map hex, split /\:/, $1;
}
$status = 1 if /addNetwork({
DESCRIPTION => $description,
IPADDRESS => $ipaddress,
IPGATEWAY => $ipgateway,
IPMASK => $ipmask,
IPSUBNET => $ipsubnet,
MACADDR => $macaddr,
STATUS => $status?"Up":"Down",
TYPE => $type,
});
}
}
### STEP 2: get physical interfaces when not a zone
if (!$zone){
foreach (`ifconfig -a`){
# resets if new interface
$ipaddress = $description = $macaddr = $status = $type = undef if /^(\S+):/;
# interface name and other data
$description = $1 if /^(\S+): /;
$ipaddress = $1 if /inet\s+(\S+)/i;
$ipmask = $1 if /\S*netmask\s+(\S+)/i;
if (/ether\s+(\S+)/i) {
# See
# https://sourceforge.net/tracker/?func=detail&atid=487492&aid=1819948&group_id=58373
$macaddr = sprintf "%02x:%02x:%02x:%02x:%02x:%02x" ,
map hex, split /\:/, $1;
}
$status = 1 if /addNetwork({
DESCRIPTION => $description,
IPADDRESS => $ipaddress,
IPGATEWAY => $ipgateway,
IPMASK => $ipmask,
IPSUBNET => $ipsubnet,
MACADDR => $macaddr,
STATUS => $status?"Up":"Down",
TYPE => $type,
});
}
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Solaris/Packages.pm 0000664 0000000 0000000 00000005120 14323200667 0025343 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Solaris::Packages;
use strict;
use warnings;
sub check {
my $params = shift;
my $common = $params->{common};
# Do not run an package inventory if there is the --nosoftware parameter
return if ($params->{config}->{nosoftware});
$common->can_run("pkginfo") || $common->can_run("pkg");
}
sub run {
my $params = shift;
my $common = $params->{common};
my $chaine ;
my @tab;
my $name;
my $version;
my $comments;
my $publisher;
if ( `uname -r` =~ /5.11/ ) {
# Solaris 11
foreach (`pkg info`) {
if (/^\s*$/) {
$common->addSoftware({
'NAME' => $name,
'VERSION' => $version,
'COMMENTS' => $comments,
'PUBLISHER' => $publisher,
});
$name = '';
$version = '';
$comments = '';
$publisher = '';
} elsif (/Name:\s+(.+)/) {
$name = $1;
} elsif (/Version:\s+(.+)/) {
$version = $1;
} elsif (/Publisher:\s+(.+)/) {
$publisher = $1;
} elsif (/Summary:\s+(.+)/) {
$comments = $1;
}
}
} else {
# Solaris 10 and lower
foreach (`pkginfo -l`) {
if (/^\s*$/) {
$common->addSoftware({
'NAME' => $name,
'VERSION' => $version,
'COMMENTS' => $comments,
'PUBLISHER' => $publisher,
});
$name = '';
$version = '';
$comments = '';
$publisher = '';
} elsif (/PKGINST:\s+(.+)/) {
$name = $1;
} elsif (/VERSION:\s+(.+)/) {
$version = $1;
} elsif (/VENDOR:\s+(.+)/) {
$publisher = $1;
} elsif (/DESC:\s+(.+)/) {
$comments = $1;
}
}
my $testrep;
$testrep=0;
#opendir(DIR,'/var/sis/') || exit ;
opendir(DIR,'/var/sis/') || ($testrep=1) ;
if ($testrep==0) {
foreach (`ls /var/sis/*.SIS`) {
$chaine= `cat $_` ;
@tab = split(/;/, $chaine);
if (/^\/var\/sis\/(\S+).SIS/){
$common->addSoftware({
'VERSION' => $tab[2],
'NAME' => $tab[0]." ($1)",
'PUBLISHER' => $tab[1],
'COMMENTS' => $1,
});
}
}
}
closedir(DIR);
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Solaris/Ports.pm 0000664 0000000 0000000 00000002632 14323200667 0024741 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Solaris::Ports;
use strict;
sub run {
my $params = shift;
my $common = $params->{common};
my $zone;
my $SystemModel;
my $aarch;
my $flag;
my $caption;
my $description;
my $name;
my $type;
if ( !$common->can_run("zonename") || `zonename` =~ /global/ ) {
# Ether pre Sol10 or in Sol10/Sol11 global zone
$zone = "global";
} else {
$zone = "";
}
if ($zone) {
chomp($SystemModel = `uname -m`);
chomp($aarch = `uname -p`);
if( $aarch eq "i386" ){
#
# For a Intel/AMD arch, we're using smbios
#
foreach(`/usr/sbin/smbios -t SMB_TYPE_PORT`) {
if(/\s+Internal Reference Designator:\s*(.+)/i ) {
$flag = 1;
$name = $1;
}
elsif ($flag && /^$/) { # end of section
$flag = 0;
$common->addPorts({
CAPTION => $caption,
DESCRIPTION => $description,
NAME => $name,
TYPE => $type,
});
$caption = $description = $name = $type = undef;
}
elsif ($flag) {
$caption = $1 if /\s+External Connector Type:.*\((.+)\)/i;
$description = $1 if /\s+External Reference Designator:\s*(.+)/i;
$type = $1 if /\s+Port Type:.*\((.+)\)/i;
}
}
}
elsif( $aarch eq "sparc" ) {
#
# For a Sparc arch, we're done
#
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Solaris/Slots.pm 0000664 0000000 0000000 00000031702 14323200667 0024736 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Solaris::Slots;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run ("prtdiag")
}
sub run {
my $params = shift;
my $common = $params->{common};
my $description;
my $designation;
my $name;
my $status;
my @pci;
my $flag;
my $flag_pci;
my $model;
my $sun_class;
chomp($model = `uname -i`);
# debug print model
#print "Model: '$model'";
$sun_class = 0;
# we map (hopfully) our server model to a known class
if ($model =~ /SUNW,SPARC-Enterprise/) { $sun_class = 1; } # M9000
if ($model =~ /SUNW,SPARC-Enterprise-T\d/) { $sun_class = 22; } # T5220
if ($model =~ /SUNW,Sun-Fire-\d/) { $sun_class = 3; } # 280R, 480R
if ($model =~ /SUNW,Sun-Fire-V\d/) { $sun_class = 3; } # V490
if ($model =~ /SUNW,Sun-Fire-T\d/) { $sun_class = 4; } # T2000
if ($model =~ /SUNW,Sun-Blade-1500/) { $sun_class = 8; } # Blade 1500 workstation
if ($model =~ /i86pc/) { $sun_class = 21; } # x86 hardware
if ($model =~ /SUNW,T5/) { $sun_class = 22; } # T5240, T5440
if ($model =~ /sun4v/) { $sun_class = 22; } # T3-x, T4-x, T5-x
#Debug
#print "sun_class : $sun_class\n";
if ( $sun_class == 0 ) {
# Default class, probably doesn't work
foreach (`prtdiag `) {
last if(/^\=+/ && $flag_pci);
next if(/^\s+/ && $flag_pci);
if($flag && $flag_pci && /^(\S+)\s+/) {
$name = $1;
}
if($flag && $flag_pci && /(\S+)\s*$/) {
$designation = $1;
}
if($flag && $flag_pci && /^\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+)/) {
$description = $1;
}
if($flag && $flag_pci && /^\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+)/) {
$status = $1;
}
if($flag && $flag_pci) {
$common->addSlot({
DESCRIPTION => $description,
DESIGNATION => $designation,
NAME => $name,
STATUS => $status,
});
}
if(/^=+\s+IO Cards/){$flag_pci = 1;}
if($flag_pci && /^-+/){$flag = 1;}
}
}
if ( $sun_class == 1 ) {
# M9000
#========================= IO Devices =========================
#
# IO Lane/Frq
#LSB Type LPID RvID,DvID,VnID BDF State Act, Max Name Model
#--- ----- ---- ------------------ --------- ----- ----------- ------------------------------ --------------------
# Logical Path
# ------------
#00 PCIx 0 8, 125, 1033 2, 0, 0 okay 133, 133 pci-pciexclass,060400 N/A
# /pci@0,600000/pci@0
#
foreach (`prtdiag -v`) {
last if(/^\=+/ && $flag_pci && $flag);
if ($flag && $flag_pci && /^(\d+)\s+(\S+)\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(\S+)\s+\S+\s+\S+\s+((\S+)-\S+)\s+(\S+).*/ ) {
$designation = "LSB " . $1;
$status = $3;
$name = $4;
$description = "[$2] $5";
$description .= " ($6)" unless ($6=~/N\/A/);
$common->addSlot({
DESCRIPTION => $description,
DESIGNATION => $designation,
NAME => $name,
STATUS => $status,
});
}
if(/^=+\S+\s+IO Devices/){$flag_pci = 1; }
if($flag_pci && /^-+/){$flag = 1;}
}
}
if ( $sun_class == 2 ) {
# to be checked
foreach (`prtdiag `) {
if (/pci/) {
@pci = split(/ +/);
$name=$pci[4]." ".$pci[5];
$description=$pci[0]." (".$pci[1].")";
$designation=$pci[3];
$status="";
$common->addSlot({
DESCRIPTION => $description,
DESIGNATION => $designation,
NAME => $name,
STATUS => $status,
});
}
}
}
if ( $sun_class == 3 ) {
# SUNW,Sun-Fire-480R
# ========================= IO Cards =========================
#
# Bus Max
# IO Port Bus Freq Bus Dev,
# Type ID Side Slot MHz Freq Func State Name Model
# ---- ---- ---- ---- ---- ---- ---- ----- -------------------------------- ----------------------
# PCI 8 B 3 33 33 3,0 ok SUNW,qlc-pci1077,2312.1077.101.2+
# PCI 8 B 3 33 33 3,1 ok SUNW,qlc-pci1077,2312.1077.101.2+
# PCI 8 B 5 33 33 5,0 ok pci-pci1011,25.4/pci108e,1000 PCI-BRIDGE
# PCI 8 B 5 33 33 0,0 ok pci108e,1000-pci108e,1000.1 device on pci-bridge
# PCI 8 B 5 33 33 0,1 ok SUNW,qfe-pci108e,1001 SUNW,pci-qfe/pci-bridg+
foreach (`prtdiag `) {
last if(/^\=+/ && $flag_pci && $flag); # End of IO Devices, next section starts here
if($flag && $flag_pci && /PCI/) {
@pci = split(/ +/);
$name=join(" ",@pci[9..$#pci]);
$description="[".$pci[0]."] ".$pci[8];
$designation=$pci[0]."/".$pci[1]."/".$pci[2]."/".$pci[3];
$status=$pci[7];
$common->addSlot({
DESCRIPTION => $description,
DESIGNATION => $designation,
NAME => $name,
STATUS => $status,
});
}
if(/^=+\S+\s+IO Cards/){
$flag_pci = 1; # Start of IO Devices section, still header to skip
}
if($flag_pci && /^-+/){
$flag = 1; # End of IO Devices header, real info starts here
}
}
}
if ( $sun_class == 21 ) {
# x86 hardware
$flag = 0;
foreach (`/usr/sbin/smbios -t SMB_TYPE_SLOT`) {
if ($flag && /^ID.*/) {
# write current slot
$common->addSlot({
DESCRIPTION => "$description ($status)",
DESIGNATION => $designation,
NAME => $name,
STATUS => $status,
});
$flag = 0;
}
elsif(/\s+Location Tag:\s+(.*)$/) {
$description = $1;
}
elsif(/\s+Slot ID:\s+(.*)$/) {
$designation= $1;
}
elsif(/\s+Type:\s+\S+\s+\((.*)\)$/) {
$name= $1;
}
elsif(/\s+Usage:\s+\S+\s+\((.*)\).*$/) {
$status = $1;
}
$flag = 1;
}
# Finally add the last card
$common->addSlot({
DESCRIPTION => "$description ($status)",
DESIGNATION => $designation,
NAME => $name,
STATUS => $status,
});
}
if ( $sun_class == 4 ) {
# SUNW,Sun-Fire-T200
#========================= IO Configuration =========================
#
# IO
#Location Type Slot Path Name Model
#----------- ----- ---- --------------------------------------------- ------------------------- ---------
#IOBD/PCIE0 PCIE 0 /pci@780/pci@0/pci@8/network@0 network-pciex8086,105e SUNW,pcie+
foreach(`prtdiag `) {
last if(/^\=+/ && $flag_pci && $flag); # End of IO Devices, next section starts here
if($flag && $flag_pci && /PCI/) {
@pci = split(/ +/);
$name=$pci[5];
$description="[".$pci[1]."] ".$pci[4];
$designation=$pci[0];
$status=" ";
if($flag && $flag_pci) {
$common->addSlot({
DESCRIPTION => $description,
DESIGNATION => $designation,
NAME => $name,
STATUS => $status,
});
}
}
if(/^=+\S+\s+IO Configuration/){
$flag_pci = 1; # Start of IO Devices section, still header to skip
}
if($flag_pci && /^-+/){
$flag = 1; # End of IO Devices header, real info starts here
}
}
}
if ( $sun_class == 8 ) {
# SUNW,Sun-Blade-1500
#================================= IO Devices =================================
#Bus Freq Slot + Name +
#Type MHz Status Path Model
#------ ---- ---------- ---------------------------- --------------------
#pci 33 MB isa/su (serial)
# okay /pci@1e,600000/isa@7/serial@0,3f8
foreach (`prtdiag `) {
last if(/^\=+/ && $flag_pci && $flag); # End of IO Devices, next section starts here
# pci 33 MB isa/su(serial) SUNW,xxx
if($flag && $flag_pci && /(\S+)\s+(\S+)\s+(\S+)\s+(\S+\s+\(\S+\))\s*(.*)/) {
$name = $5;
$designation = $3;
$description = "[$1] $4";
$status = " ";
$common->addSlot({
DESCRIPTION => $description,
DESIGNATION => $designation,
NAME => $name,
STATUS => $status,
});
}
if(/^=+\S+\s+IO Devices/){
$flag_pci = 1; # Start of IO Devices section, still header to skip
}
if($flag_pci && /^-+/){
$flag = 1; # End of IO Devices header, real info starts here
}
}
}
if ( $sun_class == 22 ) {
# SUNW,T5440
#======================================== IO Devices =======================================
#Slot + Bus Name + Model Max Speed Cur Speed
#Status Type Path /Width /Width
#-------------------------------------------------------------------------------------------
#MB/HBA PCIE scsi-pciex1000,58 LSI,1068E -- --
# /pci@400/pci@0/pci@1/scsi@0
# SPARC T3-1
#================================= IO Devices =================================
#Slot + Bus Name + Model Speed
#Status Type Path
#------------------------------------------------------------------------------
#/SYS/MB/SASHBA0 PCIE scsi-pciex1000,72 LSI,2008 --
# /pci@400/pci@1/pci@0/pci@4/scsi@0
#/SYS/MB/RISER2/PCIE2PCIE network-pciex108e,abcd SUNW,pcie-qgc --
# /pci@400/pci@1/pci@0/pci@6/network@0
# SPARC T4-4
#======================================== IO Devices =======================================
#Slot + Bus Name + Model Max Speed Cur Speed
#Status Type Path /Width /Width
#-------------------------------------------------------------------------------------------
#/SYS/MB/REM0/SASHBA0 PCIE LSI,sas-pciex1000,72 LSI,2008 -- --
# /pci@400/pci@1/pci@0/pci@0/LSI,sas@0
#/SYS/RIO/NET0 PCIE network-pciex8086,10c9 -- --
# /pci@400/pci@1/pci@0/pci@2/network@0
#/SYS/RIO/NET1 PCIE network-pciex8086,10c9 -- --
# /pci@400/pci@1/pci@0/pci@2/network@0,1
#/SYS/PCI-EM2 PCIE SUNW,qlc-pciex1077,2532 QEM3572 -- --
# /pci@400/pci@1/pci@0/pci@4/pci@0/pci@2/SUNW,qlc@0
# SPARC T5-4
#======================================== IO Devices =======================================
#Slot + Bus Name + Model Max Speed Cur Speed
#Status Type Path /Width /Width
#-------------------------------------------------------------------------------------------
#/SYS/MB/USB_CTLR PCIE usb-pciexclass,0c0330 -- --
# /pci@300/pci@1/pci@0/pci@4/pci@0/pci@6/usb@0
#/SYS/RIO/XGBE0 PCIE network-pciex8086,1528 -- --
# /pci@300/pci@1/pci@0/pci@4/pci@0/pci@8/network@0
#/SYS/MB/SASHBA0 PCIE scsi-pciex1000,87 LSI,2308_2 -- --
# /pci@300/pci@1/pci@0/pci@4/pci@0/pci@c/scsi@0
foreach (`prtdiag `) {
last if(/^\=+/ && $flag_pci && $flag); # End of IO Devices, next section starts here
# Lazy match for $name due to differences in prtdiag output:
# * the "Model" column does not always have a value
# * 5-column output on Sol10, 6-column output on Sol11
if($flag && $flag_pci && /(\S+)\s+(\S+)\s+((\S+)-\S+)\s+(\S+)\s+.*/) {
$designation = $1;
$status = " ";
$name = $3;
$description = "[$2] $4";
$description .= " ($5)" unless ($5=~/.*GT\/?x\d+|--/);
$common->addSlot({
DESCRIPTION => $description,
DESIGNATION => $designation,
NAME => $name,
STATUS => $status,
});
}
if(/^=+\S+\s+IO Devices/){
$flag_pci = 1; # Start of IO Devices section, still header to skip
}
if($flag_pci && /^-+/){
$flag = 1; # End of IO Devices header, real info starts here
}
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Solaris/Storages.pm 0000664 0000000 0000000 00000005701 14323200667 0025421 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Solaris::Storages;
use strict;
#use warning;
#sd0 Soft Errors: 0 Hard Errors: 0 Transport Errors: 0
#Vendor: HITACHI Product: DK32EJ72NSUN72G Revision: PQ08 Serial No: 43W14Z080040A34E
#Size: 73.40GB <73400057856 bytes>
#Media Error: 0 Device Not Ready: 0 No Device: 0 Recoverable: 0
#Illegal Request: 0 Predictive Failure Analysis: 0
# With -En :
#c8t60060E80141A420000011A420000300Bd0 Soft Errors: 1 Hard Errors: 0 Transport Errors: 0
#Vendor: HITACHI Product: OPEN-V -SUN Revision: 5009 Serial No:
#Size: 64.42GB <64424509440 bytes>
#Media Error: 0 Device Not Ready: 0 No Device: 0 Recoverable: 0
#Illegal Request: 1 Predictive Failure Analysis: 0
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run ("iostat")
}
sub run {
my $params = shift;
my $common = $params->{common};
my $manufacturer;
my $model;
my $description;
my $capacity;
my $name;
my $rev;
my $sn;
my $type;
my $flag_first_line;
my $rdisk_path;
foreach(`iostat -En`){
#print;
if ($flag_first_line){
## To be removed when FIRMWARE will be supported
if ($rev) {
$description .= ' ' if $description;
$description .= "FW:$rev";
}
$rdisk_path=`ls -l /dev/rdsk/${name}s2`;
if ( $rdisk_path =~ /.*->.*scsi_vhci.*/ ) {
$type="MPxIO";
} elsif( $rdisk_path =~ /.*->.*fp@.*/ ) {
$type="FC";
} elsif( $rdisk_path =~ /.*->.*scsi@.*/ ) {
$type="SCSI";
} elsif( $rdisk_path =~ /.*->.*virtual-devices.*/ ) {
$type="Virtual";
}
$common->addStorages({
NAME => $name,
MANUFACTURER => $manufacturer,
MODEL => $model,
DESCRIPTION => $description,
TYPE => $type,
FIRMWARE => $rev,
SERIALNUMBER => $sn,
DISKSIZE => $capacity
});
$manufacturer='';
$model='';
$description='';
$name='';
$rev='';
$sn='';
$type='';
}
$flag_first_line = 0;
if (/^(\S+)\s+Soft/){
$name = $1;
}
if (/^.*Product:\s*(\S+)/){
$model = $1;
}
if (/^.*<(\S+)\s*bytes/){
$capacity = $1;
$capacity = $capacity/(1024*1024);
#print $capacity."\n";
}
if (/^.*Serial No:\s*(\S+)/){
$sn = $1;
## To be removed when SERIALNUMBER will be supported
$description = "S/N:$sn";
##
}
if (/^.*Revision:\s*(\S+)/){
$rev = $1;
}
if (/^Vendor:\s*(\S+)/){
$manufacturer = $1;
$flag_first_line = 1;
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/OS/Solaris/Users.pm 0000664 0000000 0000000 00000000731 14323200667 0024731 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::OS::Solaris::Users;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run ("who")
}
# Initialise the distro entry
sub run {
my $params = shift;
my $common = $params->{common};
my %user;
# Logged on users
for (`who`){
$user{$1} = 1 if /^(\S+)./;
}
my $UsersLoggedIn = join "/", keys %user;
$common->setHardware ({ USERID => $UsersLoggedIn });
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/ 0000775 0000000 0000000 00000000000 14323200667 0024360 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/Docker.pm 0000664 0000000 0000000 00000002574 14323200667 0026135 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::Virtualization::Docker;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run("docker");
}
my @image;
sub run {
my $params = shift;
my $common = $params->{common};
foreach my $cont (`docker ps 2>/dev/null`) {
next if ($cont =~ /^CONTAINER ID/);
my $container_id=$1 if ($cont =~ /^(\w+)/i);
push @image, $container_id;
}
foreach my $c (@image) {
my $tab=`docker inspect $c`;
my $memory=$1 if ($tab =~ /\s+"Memory":\s(\d+),/);
my $name=$1 if ($tab =~ /\s+"Hostname":\s"(\w+)",/);
my $status=$1 if ($tab =~ /\s+"Status":\s"(\w+)",/);
my $vcpu=$1 if ($tab =~ /\s+"CpuShares":\s(\d+),/);
my $vmid=$1 if ($tab =~ /\s+"Id":\s"(\w+)",/);
my $ipaddr=$1 if ($tab =~ /\s+"IPAddress":\s"(.*)"/);
my $macaddr=$1 if ($tab =~ /\s+"MacAddress":\s"(.*)"/);
my $gateway=$1 if ($tab =~ /\s+"Gateway":\s"(.*)"/);
$common->addVirtualMachine({
CPUSHARES => $vcpu,
GATEWAY => $gateway,
IPADDR => $ipaddr,
MACADDR => $macaddr,
MEMORY => $memory,
NAME => $name,
STATUS => $status,
SUBSYSTEM => "Docker Container",
VMID => $vmid,
VTYPE => "Docker",
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/Jails.pm 0000664 0000000 0000000 00000002737 14323200667 0025771 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::Virtualization::Jails;
use strict;
sub check {
return(undef) unless -r '/usr/sbin/jls';
return 1;
}
my @jail;
sub run {
my $params = shift;
my $common = $params->{common};
foreach my $line (`jls -h 2>/dev/null | sed -e "1d"`) {
push @jail, $line;
}
foreach my $j (@jail) {
my @jparam=split('\s',$j);
my $vmid=$jparam[6];
my $name=$jparam[7];
my $subsystem=$jparam[9];
my $status="running";
my @ip;
my $ipv4=$jparam[39];
if ($ipv4 ne '-') {
my @ipv4=split(",",$ipv4);
foreach my $i (@ipv4) {
push @ip, $i;
}
}
my $ipv6=$jparam[41];
if ($ipv6 ne '-') {
my @ipv6=split(",",$ipv6);
foreach my $i (@ipv6) {
push @ip, $i;
}
}
my $ip=join "/", @ip;
if (defined $ip) {
$common->addVirtualMachine({
IPADDR => $ip,
NAME => $name,
STATUS => $status,
SUBSYSTEM => "FreeBSD $subsystem",
VMID => $vmid,
VTYPE => "Jail",
});
} else {
$common->addVirtualMachine({
NAME => $name,
STATUS => $status,
SUBSYSTEM => "FreeBSD $subsystem",
VMID => $vmid,
VTYPE => "Jail",
});
}
}
}
1; UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/Libvirt.pm 0000664 0000000 0000000 00000002604 14323200667 0026333 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::Virtualization::Libvirt;
use strict;
use XML::Simple;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run('virsh')
}
sub run {
my $params = shift;
my $common = $params->{common};
foreach (`virsh --readonly list --all`) {
if (/^\s*(\d+|\s+\-)\s+(\S+)\s+(\S.+)/){
my $memory;
my $vcpu;
my $name = $2;
my $status = $3;
$status =~ s/^shut off/off/;
my $xml = `virsh --readonly dumpxml $name`;
my $data = XMLin($xml);
my $vcpu = $data->{vcpu};
my $uuid = $data->{uuid};
my $vmtype = $data->{type};
if ($data->{currentMemory}->{unit}) {
$memory = $1 if $data->{currentMemory}->{content} =~ /(\d+)\d{3}$/;
$vcpu = $data->{vcpu}->{content};
} else {
$memory = $1 if $data->{currentMemory} =~ /(\d+)\d{3}$/;
$vcpu = $data->{vcpu};
}
my %machine = (
MEMORY => $memory,
NAME => $name,
UUID => $uuid,
STATUS => $status,
SUBSYSTEM => "Libvirt",
VMTYPE => $vmtype,
VCPU => $vcpu,
);
$common->addVirtualMachine(\%machine);
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/Lxc.pm 0000664 0000000 0000000 00000004700 14323200667 0025445 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::Virtualization::Lxc;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run('lxc-ls') && $common->can_run('lxc-info')
}
my $memory;
my $status;
my $name;
my $vmtype;
my $vmid;
my $vcpu=0;
my $lstatus="";
my $cpu;
my @lxc_vm;
sub run {
my $params = shift;
my $common = $params->{common};
# Retrieve name and state of the vm
foreach (`lxc-ls -1`) {
my $vm = $1 if (/^(\S+)$/);
#push (@lxc_vm, $vm);
foreach (`lxc-info -n $vm`){
$name = $1 if (/^Name:\s*(\S+)$/);
$vmid = $1 if (/^PID:\s*(\S+)$/);
$lstatus = $1 if (/^State:\s*(\S+)$/);
if ($lstatus eq "RUNNING") {
$status = "Running";
$memory = $1 if (`lxc-cgroup -n $name memory.limit_in_bytes` =~ /(\S+)/);
if (`lxc-cgroup -n $name cpuset.cpus` =~ /(\S+)/) {
$cpu = $1;
if ($cpu =~ /^(\d+)-(\d+)/){
my @tmp = ($1..$2);
$vcpu += $#tmp + 1;
} else {
$vcpu += 1;
}
}
} elsif ($lstatus eq "FROZEN") {
$status = "Paused";
} elsif ($lstatus eq "STOPPED") {
$status = "Off";
open LXC, ") {
next if (/^#.*/);
if (/^lxc.cgroup.memory.limit_in_bytes\s+=\s*(\S+)\s*$/){
$memory = $1;
}
if (/^lxc.cgroup.cpuset.cpus\s+=\s*(\S+)\s*$/){
foreach $cpu (split(/,/,$1)){
$cpu = $1;
if ($cpu =~ /(\d+)-(\d+)/){
my @tmp = ($1..$2);
$vcpu += $#tmp + 1;
} else {
$vcpu += 1;
}
}
}
}
}
}
my $machine = {
MEMORY => $memory,
NAME => $name,
STATUS => $status,
SUBSYSTEM => "LXC Container",
VCPU => $vcpu,
VMID => $vmid,
VMTYPE => "LXC",
};
$common->addVirtualMachine($machine);
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/Parallels.pm 0000664 0000000 0000000 00000015127 14323200667 0026643 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::Virtualization::Parallels;
use strict;
use warnings;
use XML::Simple;
sub check {
my $params = shift;
my $common = $params->{common};
return $common->can_run('prlctl')
}
sub run {
my $params = shift;
my $common = $params->{common};
my $config = $params->{config};
my %status_list = (
'running' => 'running',
'blocked' => 'blocked',
'paused' => 'paused',
'suspended' => 'suspended',
'crashed' => 'crashed',
'dying' => 'dying',
);
my $xmlfile = undef;
if (defined($config->{server}) && $config->{server}) {
my $dir = $config->{server};
$dir =~ s/\//_/g;
$config->{vardir} = $config->{basevardir}."/".$dir;
} elsif (defined($config->{local}) && $config->{local}) {
$config->{vardir} = $config->{basevardir}."/__LOCAL__";
}
if (-d $config->{vardir}) {
$xmlfile = $config->{vardir}."/uuid.xml";
}
my ($uuid,$mem,$status,$name,$subsys)=undef;
my $cpus = 1;
my @users = ();
# We don't want to scan user directories unless --scan-homedirs is used
return unless $config->{scanhomedirs};
foreach my $lsuser ( glob("/Users/*") ) {
$lsuser =~ s/.*\///; # Just keep the login
next if $lsuser =~ /Shared/i;
next if $lsuser =~ /^\./i; # Ignore hidden directory
next if $lsuser =~ /\ /; # Ignore directory with space in the name
next if $lsuser =~ /'/; # Ignore directory with space in the name
push(@users,$lsuser);
}
foreach my $user (@users) {
my @command = `su $user -c "prlctl list -a"`;
shift (@command);
foreach my $line ( @command ) {
chomp $line;
my @params = split(/ /, $line);
$uuid = $params[0];
$status = $params[1];
# Avoid security risk. Should never appends
next if $uuid =~ /(;\||&)/;
foreach my $infos ( `sudo -u $user prlctl list -i $uuid`) {
if ($infos =~ m/^\s\smemory\s(.*)Mb/) {
$mem = $1;
}
elsif ($infos =~ m/^\s\scpu\s([0-9]{1,2})/) {
$cpus= $1;
}
elsif ($infos =~ m/^Name:\s(.*)/) {
$name = $1;
}
elsif ($infos =~ m/^OS:\s(.*)/) {
$subsys = $1;
}
}
$uuid =~ s/{// if ($uuid =~ m/{/);
$uuid =~ s/}// if ($uuid =~ m/}/);
my ($hwUUID,$currentUUID)=undef;
# if vm is running, fetch the real uuid
if ($status eq 'running') {
my $command = "sudo -u $user prlctl exec $uuid /usr/sbin/ioreg -rd1 -c IOPlatformExpertDevice";
open(IOREG, "$command |") or die "Failed to run '$command': $!\n";
while() {
if (/^[\s|]*"(\w+)"\s*=\s*(.*)$/) {
next unless $1 eq "IOPlatformUUID";
$currentUUID = $2;
$currentUUID =~ s/\"//g;
}
}
}
if (! -e $xmlfile) {
my $uuid_xml = {
'PARALLELS' => {
'VIRTUALMACHINES' => {
'NAME' => [$name],
'PARALLELSUUID' => [$uuid], # Damned random uuid value
'GUESTUUID' => [$currentUUID], # The true and great uuid value
},
},
};
my $xs = XML::Simple->new(
ForceArray => 1,
KeepRoot => 1,
XMLDecl => '');
my $xml = $xs->XMLout($uuid_xml);
open (MYFILE, "> $xmlfile");
print MYFILE "$xml"; # write xml output to the newly created file
close (MYFILE);
$hwUUID = $currentUUID; # fetch guest uuid value, even if it's empty (vm not currently running)
} else {
my $parallels = XML::Simple->new(
ForceArray => 1,
KeepRoot => 1,
XMLDecl => '',
);
my $vm = $parallels->XMLin($xmlfile);
my $numberOfVMs = 0;
my $boolean = 0;
while (defined $vm->{PARALLELS}[0]{VIRTUALMACHINES}[$numberOfVMs]) {
$numberOfVMs+=1;
}
for (my $counter=0; $counter<$numberOfVMs; $counter++) {
if ( $vm->{PARALLELS}[0]{VIRTUALMACHINES}[$counter]{NAME}[0] eq $name ) {
# if the vm with this name exists in the file, set its GUESTUUID value, if the currentUUID isn't empty
if ( defined ($currentUUID)) {
$vm->{PARALLELS}[0]{VIRTUALMACHINES}[$counter]{GUESTUUID}[0] = $currentUUID;
}
$vm->{PARALLELS}[0]{VIRTUALMACHINES}[$counter]{PARALLELSUUID}[0] = $uuid; # if vm re-registered, parallels uuid changes
$boolean = 1;
if ( defined ($vm->{PARALLELS}[0]{VIRTUALMACHINES}[$counter]{GUESTUUID}[0])) {
$hwUUID = $vm->{PARALLELS}[0]{VIRTUALMACHINES}[$counter]{GUESTUUID}[0];
}
}
}
unless ($boolean) {
# if vm doesn't exist, push it to the file
push @{$vm->{PARALLELS}[0]{VIRTUALMACHINES}},
{
NAME => [$name],
PARALLELSUUID => [$uuid],
GUESTUUID => [$currentUUID],
};
}
open (MYFILE, "> $xmlfile");
print MYFILE $parallels->XMLout($vm);
close (MYFILE);
}
$common->addVirtualMachine ({
NAME => $name,
VCPU => $cpus,
MEMORY => $mem,
STATUS => $status,
SUBSYSTEM => $subsys,
VMTYPE => "Parallels",
UUID => $hwUUID,
});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/Qemu.pm 0000664 0000000 0000000 00000003612 14323200667 0025627 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::Virtualization::Qemu;
# With Qemu 0.10.X, some option will be added to get more and easly information (UUID, memory, ...)
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return ($common->can_run('qemu') || $common->can_run('kvm') || $common->can_run('qemu-kvm'))
}
sub run {
my $params = shift;
my $common = $params->{common};
foreach ( `ps -ef` ) {
if (m/^\S+\s+(\d+).*((qemu|kvm|(qemu-kvm)).*\-([fh]d[a-d]|drive|cdrom).*)$/) {
# match only if an qemu instance
my $name = "N/A";
my $mem = 0;
my $uuid;
my $vmtype = $3;
my $vcpu = 1;
my $pid = $1;
if (open F, "/proc/$pid/cmdline") {
my @a=split "\000-", ;
close F;
foreach my $option ( @a ) {
if ($option =~ m/^name\000(\S+)/) {
$name = $1;
} elsif ($option =~ m/^m\000(\S+)/) {
$mem = $1;
} elsif ($option =~ m/^uuid\000(\S+)/) {
$uuid = $1;
} elsif ($option =~ m/.*uuid=(\S+)/) {
$uuid = $1;
} elsif ($option =~ m/^smp\000(\d+)/) {
$vcpu = $1;
}
}
}
if ($mem == 0 ) {
# Default value
$mem = 128;
}
$common->addVirtualMachine ({
NAME => $name,
UUID => $uuid,
VCPU => $vcpu,
MEMORY => $mem,
STATUS => "running",
SUBSYSTEM => $vmtype,
VMTYPE => $vmtype,
});
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/SolarisLdoms.pm 0000664 0000000 0000000 00000002620 14323200667 0027331 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::Virtualization::SolarisLdoms;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run('ldm');
}
sub run {
my @ldoms;
my $ldom;
my @ldomdetails;
my $ldomdetail;
my $ldomname;
my $ldomstatus;
my $ldommem;
my $ldomncpu;
my $ldomuuid;
my $ldomsoftstate;
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
@ldoms = `/usr/sbin/ldm list-domain -p`;
foreach $ldom (@ldoms) {
if($ldom =~ /^DOMAIN\|name=(\S+)\|state=(\S+)\|flags=\S+\|cons=\S+\|ncpu=(\d+)\|mem=(\d+)\|.*/) {
$ldomname=$1;
$ldomstatus=$2;
$ldomncpu=$3;
$ldommem=$4/1024/1024;
$ldomsoftstate="";
@ldomdetails = `/usr/sbin/ldm list-domain -o domain -p $ldomname`;
foreach $ldomdetail (@ldomdetails) {
if($ldomdetail =~ /^DOMAIN\|.*\|softstate=(.*)$/) {
$ldomsoftstate=$1;
} elsif($ldomdetail =~ /^UUID\|uuid=(.*)$/) {
$ldomuuid=$1;
}
}
my $machine = {
MEMORY => $ldommem,
NAME => $ldomname,
UUID => $ldomuuid,
STATUS => $ldomstatus,
SUBSYSTEM => $ldomsoftstate,
VMTYPE => "Solaris Ldom",
VCPU => $ldomncpu,
};
$common->addVirtualMachine($machine);
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/SolarisZones.pm 0000664 0000000 0000000 00000004474 14323200667 0027362 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::Virtualization::SolarisZones;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return unless $common->can_run('zoneadm');
return unless $common->can_run('zonecfg');
return unless check_solaris_valid_release();
}
sub check_solaris_valid_release{
#check if Solaris 10 release is higher than 08/07
#no problem if Solaris 11
my $OSlevel;
my @rlines;
my $release_file;
my $release;
my $year;
my $month;
$OSlevel=`uname -r`;
if ( $OSlevel =~ /5.10/ ) {
$release_file = "/etc/release";
if (!open(SOLVERSION, $release_file)) {
return;
}
@rlines = ;
@rlines = grep(/Solaris/,@rlines);
$release = @rlines[0];
$release =~ m/(\d)\/(\d+)/;
$month = $1;
$year = $2;
$month =~ s/^0*//g;
$year =~ s/^0*//g;
if ($year <= 7 and $month < 8 ){
return 0;
}
}
1
}
sub run {
my @zones;
my @lines;
my $zone;
my $zoneid;
my $zonename;
my $zonestatus;
my $zonefile;
my $pathroot;
my $uuid;
my $zonetype;
my $memory;
my $memcap;
my $vcpu;
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
@zones = `/usr/sbin/zoneadm list -p`;
@zones = grep (!/global/,@zones);
foreach $zone (@zones) {
($zoneid,$zonename,$zonestatus,$pathroot,$uuid,$zonetype)=split(/:/,$zone);
$memory="";
foreach (`/usr/sbin/zonecfg -z $zonename info capped-memory`) {
if (/\s+physical:\s+(\S+)(\S)/) {
# recalculate to GB
$memory = $1 if ( $2 eq "G" ) ;
$memory = $1 / 1024 if ( $2 eq "M" ) ;
}
}
$vcpu="";
foreach (`/usr/sbin/zonecfg -z $zonename info dedicated-cpu`) {
if (/\s+ncpus:\s+\S*(\d+)/) {
$vcpu = $1;
}
}
my $machine = {
MEMORY => $memory,
NAME => $zonename,
UUID => $uuid,
STATUS => $zonestatus,
SUBSYSTEM => $zonetype,
VMTYPE => "Solaris Zones",
VMID => $zoneid,
VCPU => $vcpu,
};
$common->addVirtualMachine($machine);
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/VirtualBox.pm 0000664 0000000 0000000 00000015522 14323200667 0027022 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::Virtualization::VirtualBox;
# This module detects only all VMs create by the user who launch this module (root VMs).
use strict;
use XML::Simple;
use File::Glob ':glob';
sub check {
my $params = shift;
my $common = $params->{common};
return $common->can_run('VirtualBox') and $common->can_run('VBoxManage')
}
sub run {
my $params = shift;
my $common = $params->{common};
my $scanhomedirs = $params->{accountinfo}{config}{scanhomedirs};
my $cmd_list_vms = "VBoxManage -nologo list vms";
my ( $version ) = ( `VBoxManage --version` =~ m/^(\d\.\d).*$/ ) ;
if ( $version > 2.1 ) { # detect VirtualBox version 2.2 or higher
$cmd_list_vms = "VBoxManage -nologo list --long vms";
}
my $in = 0;
my $uuid;
my $mem;
my $status;
my $name;
foreach my $line (`$cmd_list_vms`){ # read only the information on the first paragraph of each vm
chomp ($line);
if ($in == 0 and $line =~ m/^Name:\s+(.*)$/) { # begin
$name = $1;
$in = 1;
} elsif ($in == 1 ) {
if ($line =~ m/^UUID:\s+(.*)/) {
$uuid = $1;
} elsif ($line =~ m/^Memory size:\s+(.*)/ ) {
$mem = $1;
} elsif ($line =~ m/^State:\s+(.*)\(.*/) {
$status = ( $1 =~ m/off/ ? "off" : $1 );
} elsif ($line =~ m/^\s*$/) { # finish
$in = 0 ;
next if $uuid =~ /^N\\A$/ ; #If no UUID found, it is not a virtualmachine
$common->addVirtualMachine ({
NAME => $name,
VCPU => 1,
UUID => $uuid,
MEMORY => $mem,
STATUS => $status,
SUBSYSTEM => "Oracle xVM VirtualBox",
VMTYPE => "VirtualBox",
});
$name = $status = $mem = $uuid = 'N\A'; # useless but need it for security (new version, ...)
}
}
}
if ($in == 1) { # Anormal situation ! save the current vm information ...
$common->addVirtualMachine ({
NAME => $name,
VCPU => 1,
UUID => $uuid,
MEMORY => $mem,
STATUS => $status,
SUBSYSTEM => "Oracle xVM VirtualBox",
VMTYPE => "VirtualBox",
});
}
# try to found another VMs, not exectute by root
my @vmRunnings = ();
my $index = 0 ;
foreach my $line ( `ps -ef` ) {
chomp($line);
if ( $line !~ m/^root/) {
if ($line =~ m/^.*VirtualBox (.*)$/) {
my @process = split (/\s*\-\-/, $1); #separate options
$name = $uuid = "N/A";
foreach my $option ( @process ) {
#print $option."\n";
if ($option =~ m/^comment (.*)/) {
$name = $1;
} elsif ($option =~ m/^startvm (\S+)/) {
$uuid = $1;
}
}
if ($scanhomedirs == 1 ) { # If I will scan Home directories,
$vmRunnings [$index] = $uuid; # save the no-root running machine
$index += 1;
} else {
$common->addVirtualMachine ({ # add in inventory
NAME => $name,
VCPU => 1,
UUID => $uuid,
STATUS => "running",
SUBSYSTEM => "Oracle xVM VirtualBox",
VMTYPE => "VirtualBox",
});
}
}
}
}
# If home directories scan is authorized
if ($scanhomedirs == 1 ) {
# Read every Machines Xml File of every user
foreach my $xmlMachine (bsd_glob("/home/*/.VirtualBox/Machines/*/*.xml")) {
chomp($xmlMachine);
# Open config file ...
my $configFile = new XML::Simple;
my $data = $configFile->XMLin($xmlMachine);
# ... and read it
if ($data->{Machine}->{uuid}) {
my $uuid = $data->{Machine}->{uuid};
$uuid =~ s/^{?(.{36})}?$/$1/;
my $status = "off";
foreach my $vmRun (@vmRunnings) {
if ($uuid eq $vmRun) {
$status = "running";
}
}
$common->addVirtualMachine ({
NAME => $data->{Machine}->{name},
VCPU => $data->{Machine}->{Hardware}->{CPU}->{count},
UUID => $uuid,
MEMORY => $data->{Machine}->{Hardware}->{Memory}->{RAMSize},
STATUS => $status,
SUBSYSTEM => "Oracle xVM VirtualBox",
VMTYPE => "VirtualBox",
});
}
}
foreach my $xmlVirtualBox (bsd_glob("/home/*/.VirtualBox/VirtualBox.xml")) {
chomp($xmlVirtualBox);
# Open config file ...
my $configFile = new XML::Simple;
my $data = $configFile->XMLin($xmlVirtualBox);
# ... and read it
my $defaultMachineFolder = $data->{Global}->{SystemProperties}->{defaultMachineFolder};
if ( $defaultMachineFolder != 0 and $defaultMachineFolder != "Machines" and $defaultMachineFolder =~ /^\/home\/S+\/.VirtualBox\/Machines$/ ) {
foreach my $xmlMachine (bsd_glob($defaultMachineFolder."/*/*.xml")) {
my $configFile = new XML::Simple;
my $data = $configFile->XMLin($xmlVirtualBox);
if ( $data->{Machine} != 0 and $data->{Machine}->{uuid} != 0 ) {
my $uuid = $data->{Machine}->{uuid};
$uuid =~ s/^{?(.{36})}?$/$1/;
my $status = "off";
foreach my $vmRun (@vmRunnings) {
if ($uuid eq $vmRun) {
$status = "running";
}
}
$common->addVirtualMachine ({
NAME => $data->{Machine}->{name},
VCPU => $data->{Machine}->{Hardware}->{CPU}->{count},
UUID => $uuid,
MEMORY => $data->{Machine}->{Hardware}->{Memory}->{RAMSize},
STATUS => $status,
SUBSYSTEM => "Oracle xVM VirtualBox",
VMTYPE => "VirtualBox",
});
}
}
}
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/VmWareDesktop.pm 0000664 0000000 0000000 00000002614 14323200667 0027454 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::Virtualization::VmWareDesktop;
#
# initial version: Walid Nouh
#
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return $common->can_run('/Library/Application\ Support/VMware\ Fusion/vmrun')
}
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my $uuid;
my $mem;
my $status;
my $name;
my $i = 0;
my $commande = "/Library/Application\\ Support/VMware\\ Fusion\/vmrun list";
foreach my $vmxpath ( `$commande` ) {
next unless $i++ > 0; # Ignore the first line
if (!open TMP, "<$vmxpath") {
$logger->debug("Can't open $vmxpath\n");
next;
}
my @vminfos = ;
close TMP;
foreach my $line (@vminfos) {
if ($line =~ m/^displayName =\s\"+(.*)\"/) {
$name = $1;
} elsif ($line =~ m/^memsize =\s\"+(.*)\"/) {
$mem = $1;
} elsif ($line =~ m/^uuid.bios =\s\"+(.*)\"/) {
$uuid = $1;
}
}
$common->addVirtualMachine ({
NAME => $name,
VCPU => 1,
UUID => $uuid,
MEMORY => $mem,
STATUS => "running",
SUBSYSTEM => "VmWare Fusion",
VMTYPE => "VmWare",
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/VmWareESX.pm 0000664 0000000 0000000 00000002576 14323200667 0026511 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::Virtualization::VmWareESX;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run('vmware-cmd')
}
sub run {
my $params = shift;
my $common = $params->{common};
foreach my $vmx (`vmware-cmd -l`) {
chomp $vmx;
next unless -f $vmx;
my %machineInfo;
open VMX, "<$vmx" or warn;
foreach () {
if (/^(\S+)\s*=\s*(\S+.*)/) {
my $key = $1;
my $value = $2;
$value =~ s/(^"|"$)//g;
$machineInfo{$key} = $value;
}
}
close VMX;
my $status = 'unknow';
if ( `vmware-cmd "$vmx" getstate` =~ /=\ (\w+)/ ) {
# off
$status = $1;
}
my $memory = $machineInfo{'memsize'};
my $name = $machineInfo{'displayName'};
my $uuid = $machineInfo{'uuid.bios'};
# correct uuid format
$uuid =~ s/\s+//g;# delete space
$uuid =~ s!^(........)(....)(....)-(....)(.+)$!\1-\2-\3-\4-\5!; # add dashs
my $machine = {
MEMORY => $memory,
NAME => $name,
UUID => $uuid,
STATUS => $status,
SUBSYSTEM => "VmWareESX",
VMTYPE => "VmWare",
};
$common->addVirtualMachine($machine);
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/VmWareWorkstation.pm 0000664 0000000 0000000 00000003075 14323200667 0030371 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::Virtualization::VmWareWorkstation;
#
# initial version: Walid Nouh
#
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return $common->can_run('/bin/vmrun')
}
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my $cpu;
my $cores;
my $uuid;
my $mem;
my $status;
my $name;
my $i = 0;
my $commande = "/bin/vmrun list";
foreach my $vmxpath ( `$commande` ) {
next unless $i++ > 0; # Ignore the first line
if (!open TMP, "<$vmxpath") {
$logger->debug("Can't open $vmxpath\n");
next;
}
my @vminfos = ;
close TMP;
foreach my $line (@vminfos) {
if ($line =~ m/^displayName =\s\"+(.*)\"/) {
$name = $1;
} elsif ($line =~ m/^numvcpus =\s\"+(.*)\"/){
$cpu = $1;
} elsif ($line =~ m/^cpuid.coresPerSocket =\s\"+(.*)\" /){
$cores = $1;
} elsif ($line =~ m/^memsize =\s\"+(.*)\"/) {
$mem = $1;
} elsif ($line =~ m/^uuid.bios =\s\"+(.*)\"/) {
$uuid = $1;
}
}
$common->addVirtualMachine ({
NAME => $name,
VCPU => $cpu,
CORES => $cores,
UUID => $uuid,
MEMORY => $mem,
STATUS => "running",
SUBSYSTEM => "VmWare Workstation",
VMTYPE => "VmWare",
});
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/Vmsystem.pm 0000664 0000000 0000000 00000015077 14323200667 0026557 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::Virtualization::Vmsystem;
# Initial Ocsinventory::Agent::Backend::Virtualization::Vmsystem version: Nicolas EISEN
#
# Code include from imvirt - I'm virtualized?
# http://micky.ibh.net/~liske/imvirt.html
#
# Authors:
# Thomas Liske
#
# Copyright Holder:
# 2008 (C) IBH IT-Service GmbH [http://www.ibh.de/]
#
# License:
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this package; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
##
#
# Outputs:
# Xen
# VirtualBox
# Virtual Machine
# VMware
# QEMU
# SolarisZone
#
# If no virtualization has been detected:
# Physical
#
##
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
if ( $common->can_run("zoneadm")){ # Is a solaris zone system capable ?
return 1;
}
if ( $common->can_run ("dmidecode") ) {
# 2.6 and under haven't -t parameter
my $dmidecode_ver = `dmidecode -V 2>/dev/null`;
my @SplitVersion = split(/\./, $dmidecode_ver);
if (@SplitVersion[0] > 2) {
return 1;
} elsif (@SplitVersion[0] == 2 && @SplitVersion[1] >= 7) {
return 1;
}
}
return 0;
}
sub run {
my $params = shift;
my $common = $params->{common};
my $dmidecode = '/usr/sbin/dmidecode';
my $cmd = '$dmidecode -t system';
my $dmesg = '/bin/dmesg | head -n 750';
my $status = "Physical";
my $found = 0;
# Solaris zones
my @solaris_zones;
@solaris_zones = `/usr/sbin/zoneadm list`;
@solaris_zones = grep (!/global/,@solaris_zones);
if(@solaris_zones){
$status = "SolarisZone";
$found = 1;
}
if ( -d '/proc/xen' || check_file_content('/sys/devices/system/clocksource/clocksource0/available_clocksource','xen')) {
$found = 1 ;
if (check_file_content('/proc/xen/capabilities', 'control_d')) {
# dom0 host
} else {
# domU PV host
$status = "Xen";
# those information can't be extracted from dmidecode
$common->setBios ({
SMANUFACTURER => 'Xen',
SMODEL => 'PVM domU'
});
}
}
# dmidecode needs root to work :(
if ($found == 0 and -r '/dev/mem' && -x $dmidecode) {
my $sysprod = `$dmidecode -s system-product-name`;
if ($sysprod =~ /^VMware/) {
$status = "VMware";
$found = 1;
} elsif ($sysprod =~ /^Virtual Machine/) {
$status = "Virtual Machine";
$found = 1;
} elsif ($sysprod =~ /^Microsoft Corporation/) {
$status = "Hyper-V";
$found=1;
} else {
my $biosvend = `$dmidecode -s bios-vendor`;
if ($biosvend =~ /^QEMU/) {
$status = "QEMU";
$found = 1;
} elsif ($biosvend =~ /^Xen/) { # virtualized Xen
$status = "Xen";
$found = 1;
}
}
}
# Parse loaded modules
my %modmap = (
'^vmxnet\s' => 'VMware',
'^xen_\w+front\s' => 'Xen',
);
if ($found == 0 and open(HMODS, '/proc/modules')) {
while() {
foreach my $str (keys %modmap) {
if (/$str/) {
$status = "$modmap{$str}";
$found = 1;
last;
}
}
}
close(HMODS);
}
# Let's parse some logs & /proc files for well known strings
my %msgmap = (
'VMware vmxnet virtual NIC driver' => 'VMware',
'Vendor: VMware\s+Model: Virtual disk' => 'VMware',
'Vendor: VMware,\s+Model: VMware Virtual ' => 'VMware',
': VMware Virtual IDE CDROM Drive' => 'VMware',
' QEMUAPIC ' => 'QEMU',
'QEMU Virtual CPU' => 'QEMU',
': QEMU HARDDISK,' => 'QEMU',
': QEMU CD-ROM,' => 'QEMU',
': Virtual HD,' => 'Virtual Machine',
': Virtual CD,' => 'Virtual Machine',
' VBOXBIOS ' => 'VirtualBox',
': VBOX HARDDISK,' => 'VirtualBox',
': VBOX CD-ROM,' => 'VirtualBox',
'Hypervisor signature: xen' => 'Xen',
'Xen virtual console successfully installed' => 'Xen',
'Xen reported:' => 'Xen',
'Xen: \d+ - \d+' => 'Xen',
'xen-vbd: registered block device' => 'Xen',
'ACPI: RSDP \(v\d+\s+Xen ' => 'Xen',
'ACPI: XSDT \(v\d+\s+Xen ' => 'Xen',
'ACPI: FADT \(v\d+\s+Xen ' => 'Xen',
'ACPI: MADT \(v\d+\s+Xen ' => 'Xen',
'ACPI: HPET \(v\d+\s+Xen ' => 'Xen',
'ACPI: SSDT \(v\d+\s+Xen ' => 'Xen',
'ACPI: DSDT \(v\d+\s+Xen ' => 'Xen',
);
if ($found == 0 and open(HDMSG, '/var/log/dmesg')) {
while() {
foreach my $str (keys %msgmap) {
if (/$str/) {
$status = "$msgmap{$str}";
$found = 1;
last;
}
}
}
close(HDMSG);
}
# Read kernel ringbuffer directly
if ($found == 0 and open(HDMSG, '$dmesg |')) {
while() {
foreach my $str (keys %msgmap) {
if (/$str/) {
$status = "$msgmap{$str}";
$found = 1;
last;
}
}
}
close(HDMSG);
}
if ($found == 0 and open(HSCSI, '/proc/scsi/scsi')) {
while() {
foreach my $str (keys %msgmap) {
if (/$str/) {
$status = "$msgmap{$str}";
$found = 1;
last;
}
}
}
close(HSCSI);
}
$common->setHardware ({
VMSYSTEM => $status,
});
}
sub check_file_content {
my ($file, $pattern) = @_;
return 0 unless -r $file;
my $found = 0;
open (my $fh, '<', $file) or die "Can't open file $file: $!";
while (my $line = <$fh>) {
if ($line =~ /$pattern/) {
$found = 1;
last;
}
}
close ($fh);
return $found;
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/Xen.pm 0000664 0000000 0000000 00000000227 14323200667 0025451 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::Virtualization::Xen;
$runMeIfTheseChecksFailed = ["Ocsinventory::Agent::Backend::Virtualization::Libvirt"];
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/Xen/ 0000775 0000000 0000000 00000000000 14323200667 0025112 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/Xen/XL.pm 0000664 0000000 0000000 00000004233 14323200667 0025775 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::Virtualization::Xen::XL;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
my $can_run = $common->can_run('xl');
if ($can_run) {
system('xl list');
my $exit_val = $? >> 8;
return $exit_val eq 0;
}
return $can_run;
}
sub run {
my $params = shift;
my $common = $params->{common};
# output: xm list
#
# Name ID Mem(MiB) VCPUs State Time(s)
# Domain-0 0 98 1 r----- 5068.6
# Fedora3 164 128 1 r----- 7.6
# Fedora4 165 128 1 ------ 0.6
# Mandrake2006 166 128 1 -b---- 3.6
# Mandrake10.2 167 128 1 ------ 2.5
# Suse9.2 168 100 1 ------ 1.8
# xl status
my %status_list = (
'r' => 'running',
'b' => 'blocked',
'p' => 'paused',
's' => 'shutdown',
'c' => 'crashed',
'd' => 'dying',
);
my $vmtype = 'xen';
my $subsystem = 'xl';
my @xl_list = `xl list`;
# remove first line
shift @xl_list;
foreach my $vm (@xl_list) {
chomp $vm;
my ($name, $vmid, $memory, $vcpu, $status, $time) = split(' ',$vm);
$status =~ s/-//g;
$status = ( $status ? $status_list{$status} : 'off');
my @vm_info = `xl list -l $name`;
my $uuid;
foreach my $value (@vm_info) {
chomp $value;
if ($value =~ /uuid/) {
$value =~ s/"//g;
$value =~ s/,//g;
$value =~ s/\s+.*uuid:\s+(.*)/\1/;
$uuid = $value;
last;
}
}
my $machine = {
MEMORY => $memory,
NAME => $name,
UUID => $uuid,
STATUS => $status,
SUBSYSTEM => $subsystem,
VMTYPE => $vmtype,
VCPU => $vcpu,
VMID => $vmid,
};
$common->addVirtualMachine($machine);
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/Xen/XM.pm 0000664 0000000 0000000 00000004166 14323200667 0026003 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::Virtualization::Xen::XM;
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
my $can_run = $common->can_run('xm');
if ($can_run) {
system('xm list');
my $exit_val = $? >> 8;
return $exit_val eq 0;
}
return $can_run;
}
sub run {
my $params = shift;
my $common = $params->{common};
# output: xm list
#
# Name ID Mem(MiB) VCPUs State Time(s)
# Domain-0 0 98 1 r----- 5068.6
# Fedora3 164 128 1 r----- 7.6
# Fedora4 165 128 1 ------ 0.6
# Mandrake2006 166 128 1 -b---- 3.6
# Mandrake10.2 167 128 1 ------ 2.5
# Suse9.2 168 100 1 ------ 1.8
# xm status
my %status_list = (
'r' => 'running',
'b' => 'blocked',
'p' => 'paused',
's' => 'shutdown',
'c' => 'crashed',
'd' => 'dying',
);
my $vmtype = 'xen';
my $subsystem = 'xm';
my @xm_list = `xm list`;
# remove first line
shift @xm_list;
foreach my $vm (@xm_list) {
chomp $vm;
my ($name, $vmid, $memory, $vcpu, $status, $time) = split(' ',$vm);
$status =~ s/-//g;
$status = ( $status ? $status_list{$status} : 'off');
my @vm_info = `xm list -l $name`;
my $uuid;
foreach my $value (@vm_info) {
chomp $value;
if ($value =~ /uuid/) {
$value =~ s/\(|\)//g;
$value =~ s/\s+.*uuid\s+(.*)/\1/;
$uuid = $value;
last;
}
}
my $machine = {
MEMORY => $memory,
NAME => $name,
UUID => $uuid,
STATUS => $status,
SUBSYSTEM => $subsystem,
VMTYPE => $vmtype,
VCPU => $vcpu,
VMID => $vmid,
};
$common->addVirtualMachine($machine);
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Backend/Virtualization/XenCitrixServer.pm 0000664 0000000 0000000 00000002667 14323200667 0030035 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Backend::Virtualization::XenCitrixServer;
use strict;
use warnings;
sub check {
my $params = shift;
my $common = $params->{common};
$common->can_run('xe')
}
sub run {
my $params = shift;
my $common = $params->{common};
my $hostname = `hostname`;
my $residenton;
foreach (`xe host-list params=uuid hostname=$hostname`) {
$residenton = $1 if /:\s+(.+)/;
}
foreach (`xe vm-list params=uuid resident-on=$residenton`) {
if (/:\s+(.+)/) {
my $uuid = $1 if /:\s+(.+)/;
my $fname = `xe vm-list params=name-label uuid=$uuid`;
my $name = $1 if $fname =~ /:\s+(.+)/;
my $fstatus = `xe vm-list params=power-state uuid=$uuid`;
my $status = $1 if $fstatus =~ /:\s+(.+)/;
my $fvcpu = `xe vm-list params=VCPUs-max uuid=$uuid`;
my $vcpu = $1 if $fvcpu =~ /:\s+(.+)/;
my $fmemory = `xe vm-list params=memory-actual uuid=$uuid`;
my $tmemory = $1 if $fmemory =~ /:\s+(.+)/;
my $memory = $1 if $tmemory =~ /(\d+)\d{6}$/;
my $machine = {
MEMORY => $memory,
NAME => $name,
UUID => $uuid,
STATUS => $status,
SUBSYSTEM => "xe",
VMTYPE => "XEN",
VCPU => $vcpu,
};
$common->addVirtualMachine($machine);
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Common.pm 0000664 0000000 0000000 00000072332 14323200667 0021602 0 ustar 00root root 0000000 0000000 ###############################################################################
## OCSINVENTORY-NG
## Copyleft Guillaume PROTET 2010
## Web : http://www.ocsinventory-ng.org
##
## This code is open source and may be copied and modified as long as the source
## code is always made freely available.
## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
################################################################################
package Ocsinventory::Agent::Common;
use strict;
no strict 'refs';
use warnings;
use Encode qw(encode);
=head1 NAME
Ocsinventory::Agent::Common - give common methods to other modules
=over
=item addController()
Add a controller in the inventory.
=item addUsb()
Add external usb devices in the inventory.
=item addInput()
Add internal inputs as keyboard, mouse in the inventory.
=item addModem()
Add a modem in the inventory.
=item addDrive()
Add a partition in the inventory.
=item addStorages()
Add a storage system (hard drive, USB key, SAN volume, etc) in the inventory.
=item addMemory()
Add a memory module in the inventory.
=item addPort()
Add a port module in the inventory.
=item addSlot()
Add a slot in the inventory.
=item addSoftware()
Register a software in the inventory.
=item addMonitor()
Add a monitor (screen) in the inventory.
=item addVideo()
Add a video card in the inventory.
=item addSound()
Add a sound card in the inventory.
=item addNetwork()
Register a network in the inventory.
=item addRepo()
Register a repository in the inventory.
=item setHardware()
Save global information regarding the machine.
The use of setHardware() to update USERID and PROCESSOR* information is
deprecated, please, use addUser() and addCPU() instead.
=item setBios()
Set BIOS information.
=item addCPU()
Add a CPU in the inventory.
=item addUser()
Add an user in the list of logged user.
=item addLocalUser()
Add local users in the inventory.
=item addLocalGroup()
Add local groups in the inventory.
=item addPrinter()
Add a printer in the inventory.
=item addVirtualMachine()
Add a Virtual Machine in the inventory.
=item addProcess()
Record a running process in the inventory.
=item addCamera()
Add a camera device in the inventory. Only avalaible for MacOSX
=item addIpDiscoverEntry()
IpDiscover is used to identify network interface on the local network. This
is done on the ARP level.
This function adds a network interface in the inventory.
=item setAccessLog()
What is that for? :)
=item flushXMLTags()
Clear the content of $common->{xmltags} (to use after adding it in XML)
=item addBatteries()
Add a memory module in the inventory.
=back
=cut
##################################################################################
# Ocsinventory::Agent::Common is use to give common methods to other modules #
##################################################################################
sub new {
my (undef, $params) = @_;
my $self = {};
$self->{logger} = $params->{logger};
$self->{config} = $params->{config};
$self->{xmltags} = {};
bless $self;
}
sub addController {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/DESCRIPTION DRIVER NAME MANUFACTURER PCIID PCISLOT TYPE/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{CONTROLLERS}},$content;
}
sub addUsb {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/DESCRIPTION INTERFACE MANUFACTURER SERIAL TYPE/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{USBDEVICES}},$content;
}
sub addInput {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/DESCRIPTION INTERFACE MANUFACTURER CAPTION POINTTYPE TYPE/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{INPUTS}},$content;
}
sub addModem {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/DESCRIPTION NAME/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{MODEMS}}, $content;
}
# For compatibility
sub addModems {
my $self = shift;
my $logger = $self->{logger};
$logger->debug("please rename addModems to addModem()");
$self->addModem(@_);
}
sub addDrive {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/CREATEDATE FREE FILESYSTEM LABEL SERIAL TOTAL TYPE VOLUMN/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{DRIVES}}, $content;
}
# For compatibility
sub addDrives {
my $self = shift;
my $logger = $self->{logger};
$logger->debug("please rename addDrives to addDrive()");
$self->addDrive(@_);
}
sub addStorages {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/DESCRIPTION DISKSIZE FIRMWARE MANUFACTURER MODEL NAME SERIALNUMBER SCSI_CHID SCSI_COID SCSI_LUN SCSI_UNID TYPE/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{STORAGES}}, $content;
}
# For compatibility
sub addStorage {
my $self = shift;
my $logger = $self->{logger};
$logger->debug("please rename addStorages to addStorage()");
$self->addStorage(@_);
}
sub addMemory {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/CAPACITY CAPTION DESCRIPTION ERRORCORRECTIONTYPE MANUFACTURER NUMSLOTS SERIALNUMBER SPEED TYPE/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{MEMORIES}}, $content;
}
# For compatibility
sub addMemories {
my $self = shift;
my $logger = $self->{logger};
$logger->debug("please rename addMemories to addMemory()");
$self->addMemory(@_);
}
sub addPorts{
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/CAPTION DESCRIPTION NAME TYPE/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{PORTS}}, $content;
}
# For compatibility
sub addPort {
my $self = shift;
my $logger = $self->{logger};
$logger->debug("please rename addPorts to addPort()");
$self->addPort(@_);
}
sub addSlot {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/DESCRIPTION DESIGNATION NAME STATUS/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{SLOTS}}, $content;
}
# For compatibility
sub addSlots {
my $self = shift;
my $logger = $self->{logger};
$logger->debug("please rename addSlots to addSlot()");
$self->addSlot(@_);
}
sub addSoftware {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/STATUS ARCHITECTURE COMMENTS FILESIZE FOLDER FROM INSTALLDATE NAME PUBLISHER VERSION/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{SOFTWARES}}, $content;
}
# For compatibility
sub addSoftwares {
my $self = shift;
my $logger = $self->{logger};
$logger->debug("please rename addSoftwares to addSoftware()");
$self->addSoftware(@_);
}
sub addMonitor {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/BASE64 CAPTION DESCRIPTION MANUFACTURER SERIAL UUENCODE/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{MONITORS}}, $content;
}
# For compatibility
sub addMonitors {
my $self = shift;
my $logger = $self->{logger};
$logger->debug("please rename addMonitors to addMonitor()");
$self->addMonitor(@_);
}
sub addVideo {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/CHIPSET DRVVERSION MEMORY NAME PCISLOT PCIID RESOLUTION SPEED UUID VBIOS/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{VIDEOS}}, $content;
}
# For compatibility
sub addVideos {
my $self = shift;
my $logger = $self->{logger};
$logger->debug("please rename addVideos to addVideo()");
$self->addVideo(@_);
}
sub addSound {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/DESCRIPTION MANUFACTURER NAME/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{SOUNDS}}, $content;
}
# For compatibility
sub addSounds {
my $self = shift;
my $logger = $self->{logger};
$logger->debug("please rename addSounds to addSound()");
$self->addSound(@_);
}
sub addNetwork {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/BASE BSSID DESCRIPTION DRIVER DUPLEX IPADDRESS IPDHCP IPGATEWAY IPMASK IPSUBNET MACADDR MODE MTU PCISLOT SLAVE SPEED SSID STATUS TYPE VERSION VIRTUALDEV /) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{NETWORKS}}, $content;
}
# For compatibility
sub addNetworks {
my $self = shift;
my $logger = $self->{logger};
$logger->debug("please rename addNetworks to addNetwork()");
$self->addNetwork(@_);
}
sub addRepo {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/BASEURL ENABLED EXCLUDE EXPIRE EXPIRED FILENAME LASTUPDATED MIRRORS NAME PKGS REVISION SIZE UPDATED/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{REPOSITORY}}, $content;
}
# For compatibility
sub addRepos {
my $self = shift;
my $logger = $self->{logger};
$logger->debug("please rename addRepos to addRepo()");
$self->addRepo(@_);
}
sub setHardware {
my ($self, $args, $nonDeprecated) = @_;
my $xmltags = $self->{xmltags};
my $logger = $self->{logger};
foreach my $key (qw/USERID OSVERSION PROCESSORN OSCOMMENTS CHECKSUM
PROCESSORT NAME PROCESSORS SWAP ETIME TYPE OSNAME IPADDR WORKGROUP
DESCRIPTION MEMORY UUID DNS LASTLOGGEDUSER INSTALLDATE
DATELASTLOGGEDUSER DEFAULTGATEWAY VMSYSTEM/) {
if (exists $args->{$key}) {
if ($key eq 'PROCESSORS' && !$nonDeprecated) {
$logger->debug("PROCESSORN, PROCESSORS and PROCESSORT shouldn't be set directly anymore. Please use addCPU() method instead.");
}
if ($key eq 'USERID' && !$nonDeprecated) {
$logger->debug("USERID shouldn't be set directly anymore. Please use addUser() method instead.");
}
$xmltags->{'HARDWARE'}{$key}[0] = $args->{$key};
}
}
}
sub setBios {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
foreach my $key (qw/SMODEL SMANUFACTURER SSN BDATE BVERSION BMANUFACTURER MMANUFACTURER MSN MMODEL ASSETTAG TYPE/) {
if (exists $args->{$key}) {
$xmltags->{'BIOS'}{$key}[0] = $args->{$key};
}
}
}
sub addCPU {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/CORES CPUARCH CPUSTATUS CURRENT_SPEED DATA_WIDTH HPT L2CACHESIZE LOGICAL_CPUS MANUFACTURER NBSOCKET SERIALNUMBER SOCKET SPEED THREADS TYPE VOLTAGE LOGICAL_CPUS/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{CPUS}}, $content;
# For the compatibility with HARDWARE/PROCESSOR*
my $processorn = int @{$xmltags->{CPUS}};
my $processors = $xmltags->{CPUS}[0]{SPEED}[0];
my $processort = $xmltags->{CPUS}[0]{TYPE}[0];
$self->setHardware ({
PROCESSORN => $processorn,
PROCESSORS => $processors,
PROCESSORT => $processort,
}, 1);
}
sub addUser {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $login = $args->{LOGIN};
return unless $login;
# Is the login, already in the XML ?
foreach my $user (@{$xmltags->{USERS}}) {
return if $user->{LOGIN}[0] eq $login;
}
push @{$xmltags->{USERS}},
{
LOGIN => [$login]
};
my $userString = $xmltags->{HARDWARE}->{USERID}[0] || "";
$userString .= '/' if $userString;
$userString .= $login;
$self->setHardware ({
USERID => $userString,
}, 1);
}
sub addLocalUser {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/GID HOME ID_USER LOGIN NAME SHELL/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{LOCAL_USERS}}, $content;
}
sub addLocalGroup {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/ID_GROUP MEMBER NAME/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{LOCAL_GROUPS}}, $content;
}
sub addPrinter {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/DESCRIPTION DRIVER NAME PORT/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{PRINTERS}}, $content;
}
# For compatibility
sub addPrinters {
my $self = shift;
my $logger = $self->{logger};
$logger->debug("please rename addPrinters to addPrinter()");
$self->addPrinter(@_);
}
sub addBatteries {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/CHEMISTRY DESIGNCAPACITY DESIGNVOLTAGE LOCATION MANUFACTURER MANUFACTUREDATE MAXERROR NAME OEMSPECIFIC SBDSVERSION SERIALNUMBER /) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{BATTERIES}}, $content;
}
sub addVirtualMachine {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/CORES IPADDR MEMORY NAME UUID STATUS SUBSYSTEM VMTYPE VCPU VMID/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{VIRTUALMACHINES}}, $content;
}
sub addProcess {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/COMMANDLINE CPUUSAGE PROCESSMEMORY PROCESSID STARTED TTY USERNAME VIRTUALMEMORY/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{RUNNING_PROCESSES}}, $content;
}
sub addCamera {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/MODEL UUID/){
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{RUNNING_PROCESSES}}, $content;
}
sub addPSU {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/HOTREPLACEABLE LOCATION MANUFACTURER NAME PARTNUMBER PLUGGED POWERMAX SERIALNUMBER STATUS/){
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key} if $args->{$key};
}
}
push @{$xmltags->{POWERSUPPLIES}}, $content;
}
sub addIpDiscoverEntry {
my ($self, $args) = @_;
my $xmltags = $self->{xmltags};
my $ipaddress = $args->{IPADDRESS};
my $macaddr = $args->{MACADDR};
my $name = $args->{NAME};
if (!$xmltags->{IPDISCOVER}{H}) {
$xmltags->{IPDISCOVER}{H} = [];
}
push @{$xmltags->{IPDISCOVER}{H}}, {
# If I or M is undef, the server will ignore the host
I => [$ipaddress?$ipaddress:""],
M => [$macaddr?$macaddr:""],
N => [$name?$name:"-"], # '-' is the default value returned by ipdiscover
};
}
sub setAccessLog {
my ($self, $args) = @_;
foreach my $key (qw/USERID LOGDATE/) {
if (exists $args->{$key}) {
$self->{xmlroot}{'CONTENT'}{'ACCESSLOG'}{$key}[0] = $args->{$key};
}
}
}
sub flushXMLTags {
my $self= shift;
$self->{xmltags} = {};
}
### SNMP specifics subroutines ####
sub getSnmpTable {
my ($self,$snmp_table,$baseoid,$snmp_infos) = @_;
# $snmp_infos is a hash passed for the SNMP information we want to get
# It has to be created like this :
# my $hash = {
# INFORMATION => OID,
#};
my $results={}; #The final hash which will contain one key per SNMP reference
for my $oid ( keys %$snmp_table ) {
if ( $oid =~ /$baseoid\.\d+\.\d+\.(\S+)/ ) {
my $reference=$1; #Getting the last digits of the OID separated by a dot
# Getting information if one the values from $snmp_infos hash is found for the current OID
for my $value (keys %$snmp_infos) {
if ($oid =~ /$snmp_infos->{$value}\.$reference/) {
$results->{$reference}->{$value}= $snmp_table->{$oid}
}
}
}
}
return $results;
}
sub setSnmpCommons {
my ($self,$args) = @_;
my $xmltags = $self->{xmltags};
foreach my $key (qw/IPADDR MACADDR SNMPDEVICEID NAME DESCRIPTION CONTACT LOCATION UPTIME DOMAIN TYPE / ) {
if (exists $args->{$key}) {
$xmltags->{COMMON}[0]{$key}[0] = $args->{$key};
}
}
}
sub setSnmpPrinter {
my ($self,$args) = @_;
my $xmltags = $self->{xmltags};
foreach my $key (qw/NAME SERIALNUMBER COUNTER STATUS ERRORSTATE/ ) {
if (exists $args->{$key}) {
$xmltags->{PRINTERS}[0]{$key}[0] = $args->{$key};
}
}
}
sub setSnmpSwitchInfos {
my ($self,$args) = @_;
my $xmltags = $self->{xmltags};
foreach my $key (qw/TYPE/) {
if (exists $args->{$key}) {
$xmltags->{SWITCHINFOS}[0]{$key}[0] = $args->{$key};
}
}
}
sub setSnmpFirewalls {
my ($self,$args) = @_;
my $xmltags = $self->{xmltags};
foreach my $key (qw/SERIALNUMBER SYSTEM/) {
if (exists $args->{$key}) {
$xmltags->{FIREWALLS}[0]{$key}[0] = $args->{$key};
}
}
}
sub setSnmpLoadBalancer {
my ($self,$args) = @_;
my $xmltags=$self->{xmltags};
foreach my $key (qw/SERIALNUMBER SYSTEM MANUFACTURER TYPE/ ) {
if (exists $args->{$key}) {
$xmltags->{LOADBALANCERS}[0]{$key}[0] = $args->{$key};
}
}
}
sub setSnmpBlade {
my ($self,$args) = @_;
my $xmltags = $self->{xmltags};
foreach my $key (qw/SERIALNUMBER SYSTEM/) {
if (exists $args->{$key}) {
$xmltags->{BLADES}[0]{$key}[0] = $args->{$key};
}
}
}
sub setSnmpComputer {
my ($self,$args) = @_;
my $xmltags = $self->{xmltags};
foreach my $key (qw/SYSTEM/) {
if (exists $args->{$key}) {
$xmltags->{COMPUTERS}[0]{$key}[0] = $args->{$key};
}
}
}
sub addSnmpPrinterCartridge {
my ($self,$args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/DESCRIPTION TYPE LEVEL MAXCAPACITY COLOR/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key};
}
}
push @{$xmltags->{CARTRIDGES}},$content;
}
sub addSnmpPrinterTray {
my ($self,$args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/NAME DESCRIPTION LEVEL MAXCAPACITY/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key};
}
}
push @{$xmltags->{TRAYS}},$content;
}
sub addSnmpNetwork {
my ($self,$args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/DESCRIPTION MACADDR DEVICEMACADDR SLOT STATUS SPEED TYPE DEVICEADDRESS DEVICENAME DEVICEPORT DEVICETYPE TYPEMIB IPADDR IPMASK IPGATEWAY IPSUBNET IPDHCP DRIVER VIRTUALDEV/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key};
}
}
push @{$xmltags->{NETWORKS}},$content;
}
sub addSnmpBackPlane {
my ($self,$args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/DESCRIPTION FIRMWARE MANUFACTURER REFERENCE SERIALNUMBER TYPE/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key};
}
}
push @{$xmltags->{BACKPLANE}},$content;
}
sub addSnmpCard {
my ($self,$args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/DESCRIPTION REFERENCE FIRMWARE SOFTWARE REVISION SERIALNUMBER MANUFACTURER TYPE/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key};
}
}
push @{$xmltags->{CARDS}},$content;
}
sub addSnmpFan {
my ($self,$args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/DESCRIPTION REFERENCE REVISION SERIALNUMBER MANUFACTURER TYPE/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key};
}
}
push @{$xmltags->{FANS}},$content;
}
sub addSnmpPowerSupply {
my ($self,$args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/MANUFACTURER REFERENCE TYPE SERIALNUMBER DESCRIPTION REVISION/ ) {
if (exists $args->{$key}) {
$content->{$key}[0]=$args->{$key};
}
}
push @{$xmltags->{POWERSUPPLIES}},$content;
}
sub addSnmpSwitch {
my ($self,$args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/MANUFACTURER REFERENCE TYPE SOFTVERSION FIRMVERSION SERIALNUMBER REVISION DESCRIPTION/) {
if (exists $args->{$key}) {
$content->{$key}[0]=$args->{$key};
}
}
push @{$xmltags->{SWITCHS}},$content;
}
sub addSnmpLocalPrinter {
my ($self,$args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/NAME/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key};
}
}
push @{$xmltags->{LOCALPRINTERS}},$content;
}
sub addSnmpInput {
my ($self,$args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/DESCRIPTION TYPE/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key};
}
}
push @{$xmltags->{INPUTS}},$content;
}
sub addSnmpCPU {
my ($self,$args) = @_;
my $xmltags = $self->{xmltags};
my $content = {};
foreach my $key (qw/MANUFACTURER TYPE SPEED/) {
if (exists $args->{$key}) {
$content->{$key}[0] = $args->{$key};
}
}
push @{$xmltags->{CPUS}},$content;
}
#Subroutine to add 0 in 'Sun like' MAC address if needed
sub padSnmpMacAddress {
my ($self,$mac) = @_;
my @splitedAddr = split(':', $mac);
for (@splitedAddr) {
unless ($_ =~ /\w{2}/) {
$_ = sprintf("%02s", $_);
}
}
$mac=join (':', @splitedAddr);
return $mac;
}
sub cleanXml {
my ($self,$content) = @_;
my $logger = $self->{logger};
my $clean_content = encode('UTF-8', $content, Encode::FB_DEFAULT | Encode::LEAVE_SRC | Encode::FB_XMLCREF);
$clean_content =~ tr/\x00-\x08\x0B\x0C\x0E-\x1F//d; # remove forbidden char in XML
$logger->debug("cleanXml changed content") if ($content ne $clean_content);
return $clean_content."\n";
}
#Subroutine to read XML structure (returned by XML::Simple::XMLin) and encode content in utf8.
sub readXml {
my ($self, $xml, $forcearray) = @_;
my $logger = $self->{logger};
my $content = XML::Simple::XMLin($xml, ForceArray => [@{$forcearray}]);
foreach my $key (keys %$content) {
if (grep(/^$key$/, @{$forcearray})) { #Forced array in XML parsing
$self->parseXmlArray($content->{$key},$forcearray);
} else { #Not a forced array in XML parsing
if (ref ($content->{$key}) =~ /^HASH$/ && !keys %{$content->{$key}}) { # If empty hash from XMLin()
$content->{$key} = '';
} else { encode('UTF-8', $content->{$key}, Encode::FB_DEFAULT) };
}
}
return $content;
}
#Subroutine to parse array in XML structure (returned by XML::Simple::XMLin) and encode it in utf8
sub parseXmlArray {
my ($self,$array,$forcearray) = @_;
foreach my $hash (@{$array}) {
foreach my $key (keys %$hash) {
if ( grep (/^$key$/,@$forcearray)) { #Forced array in XML parsing
$self->parseXmlArray($hash->{$key},$forcearray);
} else { #Not a forced array in XML parsing
if (ref ($hash->{$key}) =~ /^HASH$/ && !keys %{$hash->{$key}}) { # If empty hash from XMLin()
$hash->{$key} = '';
} else { encode('UTF-8', $hash->{$key}, Encode::FB_DEFAULT) };
}
}
}
}
#Subroutine to convert versions to numbers (with icutting or right padding if needed)
# We create it because Perl 5.8 does not include version comparison modules or functions
sub convertVersion {
my ($self,$version,$length) = @_;
$version =~ s/\.//g; #We convert to number
my $ver_length = length ($version);
if ($ver_length > $length) { # We cut the number
$version = substr $version, 0, $length;
} elsif ($ver_length < $length) { #We add 0 to the right
$version = substr($version . (0 x $length), 0, $length);
}
return $version;
}
#We create this subroutine because MacOSX system_profiler XML output does not give all
##the neeeded data (for videos and sounds for example)
sub get_sysprofile_devices_names {
my ($self,$type) = @_;
return(undef) unless -r '/usr/sbin/system_profiler';
my $output=`system_profiler $type`;
my $name;
my $names=[];
# Code inspired from Mac::Sysprofile 0.03 from Daniel Muey
for(split /\n/, $output) {
next if m/^\s*$/ || m/^\w/;
if(m/^\s{4}\w/) {
$name = $_;
$name =~ s/^\s+//;
$name =~ s/:.*$//;
push(@$names,$name);
}
}
return $names;
}
# Function getDmidecodeInfos.
#
sub getDmidecodeInfos {
my @dmidecode=`dmidecode`;
my ($info, $block, $type);
foreach my $line (@dmidecode){
chomp $line;
if ($line =~ /DMI type (\d+)/) {
if ($block) {
push (@{$info->{$type}}, $block);
undef $block;
}
$type=$1;
next;
}
next unless defined $type;
next unless $line =~ /^\s+ ([^:]+) : \s (.*\S)/x;
next if
$2 eq 'N/A' ||
$2 eq 'Not Specified' ||
$2 eq 'Not Present' ||
$2 eq 'Unknown' ||
$2 eq '' ||
$2 eq '' ||
$2 eq '';
$block->{$1} = $2;
}
if ($block) {
push(@{$info->{$type}}, $block);
}
return if keys %{$info} < 2;
return $info;
}
### Generic shared subroutines #####
sub can_run {
my $self = shift;
my $binary = shift;
my $logger = $self->{logger};
my $calling_namespace = caller(0);
chomp(my $binpath=`which $binary 2>/dev/null`);
return unless -x $binpath;
$self->{logger}->debug(" - $binary found");
1;
}
sub can_load {
my $self = shift;
my $module = shift;
my $logger = $self->{logger};
my $calling_namespace = caller(0);
eval "package $calling_namespace; use $module;";
return if $@;
$self->{logger}->debug(" - $module loaded");
1;
}
sub can_read {
my $self = shift;
my $file = shift;
my $logger = $self->{logger};
return unless -r $file;
$self->{logger}->debug(" - $file can be read");
1;
}
sub runcmd {
my $self = shift;
my $cmd = shift;
my $logger = $self->{logger};
return unless $cmd;
# $self->{logger}->debug(" - run $cmd");
return `$cmd`;
}
#### Old subroutines from the former Common.pm used by Download.pm #######
sub get_path{
my $self = shift;
my $binary = shift;
my $path;
my @bin_directories = qw { /usr/local/sbin/ /sbin/ /usr/sbin/ /bin/ /usr/bin/ /usr/local/bin/ /etc/ocsinventory-client/};
print "\n=> retrieving $binary...\n" if $::debug;
for (@bin_directories){
$path = $_.$binary,last if -x $_.$binary;
}
# For debbuging purposes
if ($path){
print "=> $binary is at $path\n\n" if $::debug;
} else {
print "$binary not found (Maybe it is not installed ?) - Some functionnalities may lack !!\n\n";
}
return $path;
}
sub already_in_array {
my $self = shift;
my $lookfor = shift;
my @array = @_;
foreach (@array){
if ($lookfor eq $_){
return 1 ;
}
}
return 0;
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Config.pm 0000664 0000000 0000000 00000017525 14323200667 0021562 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Config;
use strict;
use Getopt::Long;
our $VERSION = '2.10.0';
my $basedir = '';
my $default = {
'daemon' => 0,
'debug' => 0,
'devlib' => 0,
'force' => 0,
'help' => 0,
'info' => 1,
'lazy' => 0,
'local' => '',
# 'logger' => 'Syslog,File,Stderr',
'logger' => 'Stderr',
'logfacility' => 'LOG_USER',
'logfile' => '',
'password' => '',
'proxy' => '',
'realm' => '',
'remotedir' => '/ocsinventory', # deprecated, give a complete URL to
# --server instead
'server' => 'http://ocsinventory-ng/ocsinventory',
'stdout' => 0,
'tag' => '',
'user' => '',
'version' => 0,
'wait' => '',
# 'xml' => 0,
'nosoftware'=> 0,
'delaytime' => '3600', # max delay time (seconds)
'backendCollectTimeout' => '600', # timeOut of process : see Backend.pm
'scanhomedirs' => 0,
'ssl' => 1,
'ca' => '',
'snmp' => 0,
'snmptimeout' => 3,
'snmpretry' => 2,
# Other values that can't be changed with the
# CLI parameters
'version' => $VERSION,
'deviceid' => '',
'basevardir'=> $basedir.'/var/lib/ocsinventory-agent',
'logdir' => $basedir.'/var/log/ocsinventory-agent',
# 'pidfile' => $basedir.'/var/run/ocsinventory-agent.pid',
};
sub new {
my (undef, $params) = @_;
my $self = {};
bless $self;
$self->{file} = $params->{file};
$self->{config} = $default;
$self->loadFromCfgFile();
return $self;
}
sub loadFromCfgFile {
my $self = shift;
my $config;
$self->{config}{etcdir} = [];
push (@{$self->{config}{etcdir}}, '/etc/ocsinventory');
push (@{$self->{config}{etcdir}}, '/usr/local/etc/ocsinventory');
push (@{$self->{config}{etcdir}}, '/etc/ocsinventory-agent');
push (@{$self->{config}{etcdir}}, $ENV{HOME}.'/.ocsinventory'); # Should I?
my $file;
if (!$file || !-f $file) {
foreach (@{$self->{config}{etcdir}}) {
$file = $_.'/ocsinventory-agent.cfg';
last if -f $file;
}
return $config unless -f $file;
}
$self->{configfile} = $file;
if (!open (CONFIG, '<'.$file)) {
print(STDERR "Config: Failed to open $file\n");
return $config;
}
foreach () {
s/^#.+//;
if (/(\w+)\s*=\s*(.+)/) {
my $key = $1;
my $val = $2;
# Remove the quotes
$val =~ s/\s+$//;
$val =~ s/^'(.*)'$/$1/;
$val =~ s/^"(.*)"$/$1/;
$self->{config}{lc($key)} = $val;
}
}
close CONFIG;
}
sub loadUserParams {
my $self = shift;
my %options = (
"backend-collect-timeout=s" => \$self->{config}{backendCollectTimeout},
"basevardir=s" => \$self->{config}{basevardir},
"d|daemon" => \$self->{config}{daemon},
"debug" => \$self->{config}{debug},
"devlib" => \$self->{config}{devlib},
"f|force" => \$self->{config}{force},
"h|help" => \$self->{config}{help},
"i|info" => \$self->{config}{info},
"lazy" => \$self->{config}{lazy},
"l|local=s" => \$self->{config}{local},
"logfile=s" => \$self->{config}{logfile},
"nosoftware" => \$self->{config}{nosoftware},
"p|password=s" => \$self->{config}{password},
"P|proxy=s" => \$self->{config}{proxy},
"r|realm=s" => \$self->{config}{realm},
"R|remotedir=s" => \$self->{config}{remotedir},
"s|server=s" => \$self->{config}{server},
"stdout" => \$self->{config}{stdout},
"t|tag=s" => \$self->{config}{tag},
"u|user=s" => \$self->{config}{user},
"version" => \$self->{config}{version},
"w|wait=s" => \$self->{config}{wait},
# "x|xml" => \$self->{config}{xml},
"delaytime" => \$self->{config}{delaytime},
"scan-homedirs" => \$self->{config}{scanhomedirs},
"nolocal" => \$self->{config}{nolocal},
"ssl=s" => \$self->{config}{ssl},
"ca=s" => \$self->{config}{ca},
"snmp=s" => \$self->{config}{snmp},
"snmptimeout=s" => \$self->{config}{snmptimeout},
"snmpretry=s" => \$self->{config}{snmpretry},
);
$self->help() if (!GetOptions(%options) || $self->{config}{help});
$self->version() if $self->{config}{version} eq 1;
}
sub help {
my ($self, $error) = @_;
if ($error) {
chomp $error;
print "ERROR: $error\n\n";
}
if ($self->{configfile}) {
print STDERR "Setting initialised with values retrieved from ".
"the config found at ".$self->{configfile}."\n";
}
print STDERR "\n";
print STDERR "Usage:\n";
print STDERR "\t--backend-collect-timeout set a max delay time of one action (search package id, ...) is set (".$self->{config}{backendCollectTimeout}.")\n";
print STDERR "\t--basevardir=/path indicate the directory where should the agent store its files (".$self->{config}{basevardir}.")\n";
print STDERR "\t-d --daemon detach the agent in background (".$self->{config}{daemon}.")\n";
print STDERR "\t --debug debug mode (".$self->{config}{debug}.")\n";
print STDERR "\t --devlib search for Backend mod in ./lib only (".$self->{config}{devlib}.")\n";
print STDERR "\t-f --force always send data to server (Don't ask before) (".$self->{config}{force}.")\n";
print STDERR "\t-i --info verbose mode (".$self->{config}{info}.")\n";
print STDERR "\t--lazy do not contact the server more than one time during the PROLOG_FREQ (".$self->{config}{lazy}.")\n";
print STDERR "\t-l --local=DIR do not contact server but write inventory in DIR directory in XML (".$self->{config}{local}.")\n";
print STDERR "\t --logfile=FILE log message in FILE (".$self->{config}{logfile}.")\n";
print STDERR "\t-p --password=PWD password for server auth\n";
print STDERR "\t-P --proxy=PROXY proxy address. e.g: http://user:pass\@proxy:port (".$self->{config}{proxy}.")\n";
print STDERR "\t-r --realm=REALM realm for server auth. e.g: 'Restricted Area' (".$self->{config}{realm}.")\n";
print STDERR "\t-s --server=uri server uri (".$self->{config}{server}.")\n";
print STDERR "\t --stdout do not write or post the inventory but print it on STDOUT\n";
print STDERR "\t-t --tag=TAG use TAG as tag (".$self->{config}{tag}."). Will be ignored by server if a value already exists.\n";
print STDERR "\t-u --user=USER user for server auth (".$self->{config}{user}.")\n";
print STDERR "\t --version print the version\n";
print STDERR "\t-w --wait=seconds wait a random period before contacting server like --daemon does (".$self->{config}{wait}.")\n";
# print STDERR "\t-x --xml write output in a xml file ($self->{config}{xml})\n";
print STDERR "\t--nosoftware do not return installed software list (".$self->{config}{nosoftware}.")\n";
print STDERR "\t--delaytime set a max delay time (in second) if no PROLOG_FREQ is set (".$self->{config}{delaytime}.")\n";
print STDERR "\t--scan-homedirs permit to scan home user directories (".$self->{config}{scanhomedirs}.")\n" ;
print STDERR "\t--ssl=0|1 disable or enable SSL communications check (".$self->{config}{ssl}.")\n" ;
print STDERR "\t--ca=FILE path to CA certificates file in PEM format (".$self->{config}{ca}.")\n" ;
print STDERR "\n";
print STDERR "Manpage:\n";
print STDERR "\tSee man ocsinventory-agent\n";
print STDERR "\n";
print STDERR "Ocsinventory-Agent is released under GNU GPL 2 license\n";
exit 1;
}
sub version {
print "Ocsinventory unified agent for UNIX, Linux and MacOSX (".$VERSION.")\n";
exit 0;
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Encrypt.pm 0000664 0000000 0000000 00000000227 14323200667 0021770 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Encrypt;
use MIME::Base64;
sub getClearText {
my ($encodedpass) = @_;
return decode_base64($encodedpass);
}
1; UnixAgent-2.10.0/lib/Ocsinventory/Agent/Hooks.pm 0000664 0000000 0000000 00000006025 14323200667 0021431 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Hooks;
# This package give possibility to use hooks in unified unix agent.
use strict;
use warnings;
#use FindBin qw($Bin);
sub new {
my (undef, $context) = @_;
my $self = {};
$self->{accountinfo} = $context->{accountinfo};
$self->{accountconfig} = $context->{accountconfig};
my $logger = $self->{logger}=$context->{logger};
$self->{config} = $context->{config};
$self->{dontuse} = 1;
my $modulefile;
foreach (@{$self->{config}->{etcdir}}) {
$modulefile = $_.'/modules.conf';
if (-f $modulefile) {
if (do $modulefile) {
$logger->debug("Turns hooks on for $modulefile");
$self->{dontuse} = 0;
last;
} else {
$logger->debug("Failed to load `$modulefile': $?");
}
}
}
if ($self->{dontuse}) {
$logger->debug("No modules will be used.");
} else {
my $ocsAgentServerUri;
# to avoid a warning if $self->{config}->{server} is not defined
if ($self->{config}->{server}) {
$ocsAgentServerUri = "http://".$self->{config}->{server}.$self->{config}->{remotedir};
}
if ($self->{config}->{debug}) {
$::debug = 2;
}
}
# Create objects for modules
foreach my $package (searchModules(\%Ocsinventory::Agent::Modules::)){
my $module = new $package($context);
my $name = $module->{structure}->{name};
# Store the reference in a key to access modules easily
$self->{modules}->{$name}=$module;
}
bless $self;
}
# This function recursively searches for modules in a given namespace
# Param: a hash reference to the namespace
# Returns: an array with modules fully qualified names
sub searchModules {
my $symbols_href = shift;
my @modules_list = ();
my %symbols_h = %{$symbols_href};
my @symbols_a = sort(keys(%symbols_h));
foreach(@symbols_a){
if ($_ eq 'new'){
# Found a "new" method -> this is a usable module
my $module_fqn = $symbols_h{$_};
# Keep the module fqn, without '*' at start
$module_fqn =~ s/\*?(.+)::new$/$1/;
push(@modules_list, $module_fqn);
} elsif (substr($_, -2) eq '::') {
# If we meet a package, continue walking
push(@modules_list, searchModules($symbols_h{$_}));
}
}
return @modules_list;
}
sub run {
my ($self, $args, $moduleparam) = @_;
return if $self->{dontuse};
my $name = $args->{name}; #type of hook asked
my $logger = $self->{logger};
$logger->debug("Calling handlers : `$name'");
# Launching hook for modules if not 'undef' and if modules are not disabled by start_handler
for (keys %{$self->{modules}}) {
my $module = $self->{modules}->{$_};
unless ($module->{disabled}) {
my $hook = $module->{structure}->{$name};
if ($hook) {
$module->$hook($moduleparam);
}
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Modules/ 0000775 0000000 0000000 00000000000 14323200667 0021415 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Modules/Apache/ 0000775 0000000 0000000 00000000000 14323200667 0022576 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Modules/Apache/Vhosts/ 0000775 0000000 0000000 00000000000 14323200667 0024064 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Modules/Apache/Vhosts/Common.pm 0000664 0000000 0000000 00000024610 14323200667 0025655 0 ustar 00root root 0000000 0000000 ###############################################################################
# Apache::Vhosts::Common - Common stuff for apache vhosts inventory
#
# Author: Linkbynet
###############################################################################
package Ocsinventory::Agent::Modules::Apache::Vhosts::Common;
=head1 NAME
Apache::Vhosts::Common - Lib for common operations in vhosts inventory
=head1 DESCRIPTION
This package is meant to contain common functions used by OCS modules for
Apache virtualhosts.
For example, we could have two OCS modules:
=over
=item ApacheVhostsPackaged
which would deal with packaged apache setups
=item ApacheVhostsCompiled
which would deal with compiled apache versions
=back
At different times, these modules still would need to do the same things, such
as parsing apache configuration files, reading and extracting information from
a vhost dump, reading a x509 certificate with openssl, ...
To avoid code duplication, the specific modules can call the functions
contained in this common package.
=head2 Exports
The module exports the following functions:
=over
=item C
=item C
=back
=cut
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(&readVhostsDump &readVhostConfFile);
use strict;
use warnings;
#### BEGIN: Define regexes
# Useful lines in vhosts dump (NameVirtualHosts and IP vhosts only)
my $dumpline_name_re = qr/^port ([0-9]+) namevhost (\S+) \((\S+):([0-9]+)\)/;
my $dumpline_ip_re = qr/^([0-9.]+):([0-9]+)\s+(\S+) \((\S+):([0-9]+)\)/;
# "subject=" line of openssl x509 command output (used to extract CN)
my $subject_cn_re = qr/^subject=.*\/CN=([^\s\/]+).*$/;
# Simplistic email address pattern
my $damn_simple_email_re = qr/.+\@.+\..+/;
#### END: Define regexes
=head2 readVhostsDump()
Return an array of hashes with the virtualhosts found thanks to Apache's vhosts
dump (C command).
=head3 Return type
The function returns a reference to an array of hashes.
=head3 Process
The function's workflow is as follows:
=over
=item 1
Open C command output, with the current configuration file
=item 2
Read dump line by line to match IP-based or name-based virtualhost information
(both types of lines should be recognized):
port 80 namevhost mynamevhost.fr (/etc/httpd/.../10-mynamevhost.conf:50)
10.0.0.1:80 myvhost myipvhost.fr (/etc/httpd/.../20-myipvhost.conf:1)
=item 3
Create a hash with the virtualhost's data
We put the following attributes in it:
(string) computedname, (int) port, (string) srvname,
(string) vhostfile, (string) vhostline, (string) docroot, (bool) ssl
At this stage we do not know docroot or ssl, so they are "/nonexistent" and
false (0), respectively.
=item 4
Push the vhost hash to the array.
=back
=head3 Return example
[
{
'computedname' => "[httpd] myvhost.fr:80",
'port' => 80,
'srvname' => 'myvhost.fr',
'vhostfile' => '/etc/httpd/conf.d/10-myvhost.conf',
'vhostline' => 1,
'docroot' => '/nonexistent',
'ssl' => 0
},
{
'computedname' => "[httpd] myvhost.fr:443",
'port' => 443,
'srvname' => 'myvhost.fr',
'vhostfile' => '/etc/httpd/conf.d/10-myvhost.conf',
'vhostline' => 20,
'docroot' => '/nonexistent',
'ssl' => 0
}
]
=head3 Calling
my $vhosts = readVhostsDump($httpd_bin, $httpd_conf_file, $logger);
=over
=item Parameter: $httpd_bin (string)
Path to the httpd binary to execute (for example: C).
Specific options (such as C<-D> parameters) may be added to the string.
=item Parameter: $httpd_conf_file (string)
Path to the main httpd configuration file (for example:
C).
=item Parameter: $logger (reference to OCS logger instance)
To make use of OCS logging capabilities within the function.
=back
=cut
sub readVhostsDump {
my ($httpd_bin, $httpd_conf_file, $logger) = @_;
my @vhosts = ();
# 2>&1 because some very old Apache versions write the vhosts dump
# on stderr!
open(my $DUMPFILE, "$httpd_bin -S -f $httpd_conf_file 2>&1 |")
or die("Cannot open \$(httpd -S -f $httpd_conf_file) $!");
while (<$DUMPFILE>) {
chomp;
s/^\s+//; # lstrip
my ($ip, $port, $srvname, $vhostfile, $vhostline);
if ($_ =~ $dumpline_name_re) {
($port, $srvname, $vhostfile, $vhostline) = ($1, $2, $3, $4);
} elsif ($_ =~ $dumpline_ip_re) {
($ip, $port, $srvname, $vhostfile, $vhostline) = ($1, $2, $3, $4, $5);
}
if (defined($port)) { # sufficient test to know if line was found
my %vhost = (
'computedname' => "$srvname:$port",
'port' => int($port),
'srvname' => $srvname,
'vhostfile' => $vhostfile,
'vhostline' => int($vhostline),
'docroot' => '/nonexistent',
'ssl' => 0
);
push(@vhosts, \%vhost);
}
}
close($DUMPFILE);
return \@vhosts;
}
=head2 readVhostConfFile()
Enhance a virtualhost's information with elements found when parsing the
vhost's configuration file.
=head3 Return type
The function returns nothing.
It only operates on the (referenced) vhost hash it got in parameter.
=head3 Process
The function must read the apache configuration file in which the vhost gets
defined ( block).
The path to the particular configuration file and the line number of the vhost
declaration are known in the C and C attributes, thanks
to the vhost dump.
The function's process, for the given vhost, is as follows:
=over
=item 1
Open the configuration file at C
=item 2
Read line by line, waiting to be at correct line number (C) to
start searching for information.
=item 3
Search for the following information in the and enhance the
given vhost hash with:
=over
=item *
docroot (string)
the value of the C directive
=item *
ssl (bool)
we turn it to true if we find a C directive
=item *
sslcertpath (string)
value of the C directive, if such a directive is present
=back
=item 4
File reading stops when we find the C<< >> closing block
(in case multiple vhosts are declared in the same configuration file).
=back
=head3 Calling
foreach my $vhost (@$vhosts) # Generally
{
readVhostConfFile($vhost, $httpd_basedir);
}
=over
=item Parameter: $vhost (reference to hash)
The virtualhost hash to enhance.
=item Parameter: $httpd_basedir (string)
The path to base directory of httpd, in case we encounter a relative path
in C and need to complete it.
B: the given path is expected to end with a slash '/', for example:
"/etc/httpd/"
=back
=cut
sub readVhostConfFile {
my ($vhost, $relpath_prefix) = @_;
my $nr = 0;
open(my $VHOST_FILE, '<', $vhost->{'vhostfile'})
or die ("Cannot open $vhost->{'vhostfile'}");
while (my $vline = <$VHOST_FILE>) {
# Waiting the correct line to start reading
next if ++$nr < $vhost->{'vhostline'};
$vline =~ s/^\s+//; # lstrip
# Get various vhost properties
# -- DocumentRoot
if ($vline =~ m/^DocumentRoot ["']?([^\s'"]+)["']?/i) {
$vhost->{'docroot'} = $1;
}
# -- SSLEngine (bool)
elsif ($vline =~ m/^SSLEngine on/i) {
$vhost->{'ssl'} = 1;
}
# -- SSLCertificateFile path
elsif ($vline =~ m/^SSLCertificateFile ["']?([^\s'"]+)["']?/i) {
$vhost->{'sslcertpath'} = $1;
readVhostSSLCert($vhost, $relpath_prefix);
}
# Stop reading on block closing tag
last if $vline =~ m@^@i;
}
close($VHOST_FILE);
}
###############################################################################
# readVhostSSLCert() - read a vhost's SSL certificate to get its details
#
# Invoking:
# readVhostSSLCert($vhost, $relpath_prefix)
#
# Params:
# - $vhost - a reference to the vhost hash
# - $relpath_prefix - the prefix to use in case the SSLCertificateFile path
# is a relative one, in order to make it an absolute path
#
# Returns:
# nothing.
#
# We read the certificate with an "openssl x509" command.
# We try to retrieve the following fields:
#
# - "subject" (specifically to get the CN)
# - "notBefore" and "notAfter" dates
# - "email" (we catch the first email returned)
#
# The certificate details found here are gently stuffed in
# $vhost->{'sslcertdetails'}, as follows:
#
# {
# # (in a vhost here)
# # [...]
# 'srvname' => 'myvhost.fr',
# 'ssl' => 1,
# 'sslcertpath' => 'conf/ssl/myvhost.fr.crt',
# 'sslcertdetails' => {
# 'cn' => 'myvhost.fr',
# 'startdate' => '31/12/2012',
# 'enddate' => '31/12/2042',
# 'email' => 'certadmin-email@example.com'
# }
# }
sub readVhostSSLCert {
my ($vhost, $relpath_prefix) = @_;
$vhost->{'sslcertdetails'} = ();
my $sslcertpath = $vhost->{'sslcertpath'};
my $absolute = (substr($sslcertpath, 0, 1) eq '/');
if (!$absolute) {
$sslcertpath = "${relpath_prefix}${sslcertpath}";
}
open(my $OPENSSL_CMD, "openssl x509 -in \"$sslcertpath\" -noout -subject -dates -email |");
while (my $oline = <$OPENSSL_CMD>) {
if ($oline =~ $subject_cn_re) {
$vhost->{'sslcertdetails'}->{'cn'} = $1;
} elsif ($oline =~ m/^notBefore=(.+)$/) {
$vhost->{'sslcertdetails'}->{'startdate'} = formatDate($1);
} elsif ($oline =~ m/^notAfter=(.+)$/) {
$vhost->{'sslcertdetails'}->{'enddate'} = formatDate($1);
} elsif ($oline =~ $damn_simple_email_re) {
chomp $oline;
$vhost->{'sslcertdetails'}->{'email'} = $oline;
# stop processing from the first email address
# (it should be the last line of the command output)
last;
}
}
close($OPENSSL_CMD);
}
###############################################################################
# formatDate() - reformat date, with help of system command date(1)
#
# Invoking:
# formatDate($date)
#
# Params:
# - $date - the date string to reformat, in a format parsable by date(1)
#
# Returns:
# the ISO 8601 (%Y-%m-%d) formatted date (string)
#
sub formatDate {
my ($date) = @_;
my $formattedDate = `date --date="$date" --iso-8601`;
chomp $formattedDate;
return $formattedDate;
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Modules/Apache/VhostsEL.pm 0000664 0000000 0000000 00000012574 14323200667 0024654 0 ustar 00root root 0000000 0000000 ################################################################################
## Author: Linkbynet
##
## This code is open source and may be copied and modified as long as the source
## code is always made freely available.
## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
##
## #############################################################################
##
## This module retrieves information about Apache virtualhosts.
##
## It handles setups where Apache was installed by package (Enterprise Linux
## distributionsi family: RHEL, CentOS, Fedora) with configuration in standard
## dir /etc/httpd.
##
## Information gets written to tags at XPaths:
##
## /REQUEST/CONTENT/APACHE_VHOST
## /REQUEST/CONTENT/APACHE_VHOST_CERTIFICATE
##
## Example:
##
##
##
## /var/www/example.com
## example.com:443
## example.com
## 443
##
##
##
## example.com
## 30/06/2023
## 01/07/2013
## example.com:443
## certmaster@example.com
##
##
##
################################################################################
package Ocsinventory::Agent::Modules::Apache::VhostsEL;
use strict;
use warnings;
use Ocsinventory::Agent::Modules::Apache::Vhosts::Common;
sub new {
my $name = "apachevhosts_el"; # Set the name of your module here
my (undef,$context) = @_;
my $self = {};
# Create a special logger for the module
$self->{logger} = new Ocsinventory::Logger ({
config => $context->{config}
});
$self->{logger}->{header} = "[$name]";
$self->{context} = $context;
$self->{structure} = {
name => $name,
start_handler => $name."_start_handler", # or undef if don't use this hook
prolog_writer => undef, # or undef if don't use this hook
prolog_reader => undef, # or undef if don't use this hook
inventory_handler => $name."_inventory_handler", # or undef if don't use this hook
end_handler => undef # or undef if don't use this hook
};
# Path to httpd bin
$self->{modinfos}->{httpd_bin} = '/usr/sbin/httpd';
# Path to httpd dir in /etc
# (basis for relative paths or SSLCertificateFile, for example)
$self->{modinfos}->{httpd_basedir} = '/etc/httpd/';
# Path to httpd conf dir
$self->{modinfos}->{httpd_confdir} = '/etc/httpd/conf';
# Path to httpd main conf file
$self->{modinfos}->{httpd_conf_file} = '/etc/httpd/conf/httpd.conf';
bless $self;
}
######### Hook methods ############
sub apachevhosts_el_start_handler { # Use this hook to test prerequisites needed by module and disble it if needed
my $self = shift;
my $logger = $self->{logger};
my $prerequisites = 1;
# TESTS:
#
# 1 - Apache HTTPD server is installed the packet way (conf dir present)
# 2 - We can execute the httpd binary
# 3 - We can read the main conf file (httpd.conf or equivalent)
if (! -d $self->{modinfos}->{httpd_confdir}) {
# No apache found on this server (or not in the expected place)
$logger->debug("- no $self->{modinfos}->{httpd_confdir} directory found");
$prerequisites = 0;
} elsif (! -x $self->{modinfos}->{httpd_bin}) {
$logger->debug("- no executable $self->{modinfos}->{httpd_bin} found");
$prerequisites = 0;
} elsif (! -f $self->{modinfos}->{httpd_conf_file}) {
$logger->debug("- did not find $self->{modinfos}->{httpd_conf_file} file");
$prerequisites = 0;
}
if ($prerequisites == 0) {
$self->{disabled} = 1; # Use this to disable the module
$logger->debug("Humm my prerequisites are not OK...disabling module :( :( ");
}
}
sub apachevhosts_el_inventory_handler { # Use this hook to add or modify entries in the inventory XML
my $self = shift;
my $logger = $self->{logger};
my $common = $self->{context}->{common};
$logger->debug(__PACKAGE__);
# Reading httpd -S output
my $vhosts = readVhostsDump($self->{modinfos}->{httpd_bin}, $self->{modinfos}->{httpd_conf_file}, $logger);
# Enhancing information by parsing each vhost's configuration
foreach my $vhost (@$vhosts) {
readVhostConfFile($vhost, $self->{modinfos}->{httpd_basedir});
}
# Write OCS XML
foreach my $vhost (@$vhosts) {
push @{$common->{'xmltags'}->{'APACHE_VHOST'}}, {
"NAME" => [$vhost->{'computedname'}],
"URL" => [$vhost->{'srvname'}],
"DIRECTORY" => [$vhost->{'docroot'}],
"PORT_NUMBER" => [$vhost->{'port'}]
};
if ($vhost->{'ssl'}) {
push @{$common->{'xmltags'}->{'APACHE_VHOST_CERTIFICATE'}}, {
"SITE" => [$vhost->{'computedname'}],
"DOMAINNAME" => [$vhost->{'sslcertdetails'}->{'cn'}],
"REGISTRATIONDATE" => [$vhost->{'sslcertdetails'}->{'startdate'}],
"EXPIRATIONDATE" => [$vhost->{'sslcertdetails'}->{'enddate'}],
"EMAIL" => [$vhost->{'sslcertdetails'}->{'email'}]
};
}
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Modules/Databases/ 0000775 0000000 0000000 00000000000 14323200667 0023304 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Modules/Databases/Oracle.pm 0000664 0000000 0000000 00000006571 14323200667 0025060 0 ustar 00root root 0000000 0000000 ################################################################################
## Author: Linkbynet
##
## This code is open source and may be copied and modified as long as the source
## code is always made freely available.
## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
##
## #############################################################################
##
## This module finds and retrieves information about Oracle instances.
##
## First elements are taken from the /etc/oratab file. For each instance listed
## in it, we get the precise version number (with tnsping utility) and bundle
## name by reading the file below:
##
## $ORACLE_HOME/inventory/Components21/oracle.server/*/context.xml
##
## Information gets written to tags at XPaths:
##
## /REQUEST/CONTENT/ORACLE_INSTANCE
##
## Example:
##
##
##
## 0
## Standard
## EXDB01
## 11.2.0.4.0
##
##
##
################################################################################
package Ocsinventory::Agent::Modules::Databases::Oracle;
use strict;
use warnings;
use Ocsinventory::Agent::Modules::Databases::Oracle::Instances;
sub new {
my $name = "oracleinstances"; # Set the name of your module here
my (undef,$context) = @_;
my $self = {};
# Create a special logger for the module
$self->{logger} = new Ocsinventory::Logger ({
config => $context->{config}
});
$self->{logger}->{header} = "[$name]";
$self->{context} = $context;
$self->{structure} = {
name => $name,
start_handler => $name."_start_handler", # or undef if don't use this hook
prolog_writer => undef, # or undef if don't use this hook
prolog_reader => undef, # or undef if don't use this hook
inventory_handler => $name."_inventory_handler", # or undef if don't use this hook
end_handler => undef # or undef if don't use this hook
};
bless $self;
}
######### Hook methods ############
sub oracleinstances_start_handler { # Use this hook to test prerequisites needed by module and disble it if needed
my $self = shift;
my $logger = $self->{logger};
my $prerequisites = 1;
if (!(-f '/etc/oratab' && -r '/etc/oratab')) {
$logger->debug("- no readable /etc/oratab file");
$prerequisites = 0;
}
if ($prerequisites == 0) {
$self->{disabled} = 1; # Use this to disable the module
$logger->debug("Humm my prerequisites are not OK...disabling module :( :( ");
}
}
sub oracleinstances_inventory_handler { # Use this hook to add or modify entries in the inventory XML
my $self = shift;
my $logger = $self->{logger};
my $common = $self->{context}->{common};
$logger->debug(__PACKAGE__);
my $database = getInstances();
# Write to OCS XML
foreach my $instance (keys(%$database)) {
push @{$common->{xmltags}->{ORACLE_INSTANCE}}, {
'NAME' => [$instance],
'AUTOSTART' => [$database->{$instance}->{'AUTOSTART'}],
'VERSION' => [$database->{$instance}->{'VERSION'}],
'BUNDLE' => [$database->{$instance}->{'BUNDLE'}]
};
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Modules/Databases/Oracle/ 0000775 0000000 0000000 00000000000 14323200667 0024511 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/Modules/Databases/Oracle/Instances.pm 0000664 0000000 0000000 00000013534 14323200667 0027004 0 ustar 00root root 0000000 0000000 ################################################################################
# Oracle::Instances - Common stuff to get Oracle instances and versions
#
# Author: Linkbynet
################################################################################
package Ocsinventory::Agent::Modules::Databases::Oracle::Instances;
=head1 NAME
Oracle::Instances - Lib for Oracle instances and versions retrieval
=head1 DESCRIPTION
This module provides a function to retrieve information about Oracle instances
on the current server.
To do so, the function reads the /etc/oratab file to find instances and then:
=over
=item 1
Checks the existence of the ORACLE_HOME directory.
=item 2
Add (ORACLE_SID, ORACLE_HOME, AUTOSTART) to the databases hash.
=item 3
Go and find server version and bundle for each ORACLE_HOME.
This information is found by executing the C command and by reading
the following XML file:
$ORACLE_HOME/inventory/Components21/oracle.server/*/context.xml
The following bundles are known: SE1 (Standard Edition One), SE (Standard
Edition), EE (Enterprise Edition), XE (Express Edition).
=item 4
Returns the database hash as follows:
{
'SID' => {
'BUNDLE' => 'Standard',
'AUTOSTART' => 0,
'ORA_HOME' => '/home/oracle/oracle/product/11.2.0',
'VERSION' => '11.2.0.4.0'
}
};
=back
Optionally, you can call C to return only the hash of versions
and bundles, instead of the complete instances hash:
{
'/home/oracle/oracle/product/11.2.0' => {
'BUNDLE' => 'Standard',
'VERSION' => '11.2.0.4.0'
}
};
In that case, you just have to pass parameter 1 (integer one) when calling the
function.
=head2 Exports
The module exports the C function.
=cut
use Exporter;
our @ISA = qw(Exporter);
our @EXPORT = qw(&getInstances);
use strict;
use warnings;
######### BEGIN: Constants ############
# Known Oracle editions. The two-letter codes are the ones which can be
# encountered in the context.xml file.
my %bundles = (
'SE1' => 'Standard One',
'SE' => 'Standard',
'EE' => 'Enterprise',
'XE' => 'Express'
);
######### END: Constants ############
=head2 getInstances()
=head3 Synopsis
getInstances($version_only)
where $versions_only is a integer (tested as a bool)
my $database = getInstances()
my $versions = getInstances(1)
=head3 Return values
The function returns a hash reference containing the instances or versions.
=cut
sub getInstances {
my $versions_only = shift;
my %database;
my %versions;
# First, read the /etc/oratab to find out Oracle instances
# Here we already get the SID, path and autostart
open(my $ORATAB, '<', '/etc/oratab') or die("Cannot open /etc/oratab $!");
while (my $oratab_line = <$ORATAB>) {
chomp $oratab_line;
next if $oratab_line =~ /^(#|$)/; # skip comments and empty lines
my ($ora_sid, $ora_home, $dbstart_yn) = split(/:/, $oratab_line);
# Keep existing instances only
if (-d $ora_home) {
$database{$ora_sid} = {
'ORA_HOME' => $ora_home,
'AUTOSTART' => $dbstart_yn eq 'Y' ? 1 : 0
};
}
}
close($ORATAB);
# Retrieve version and bundle information in %versions
# and put information in global %database hash too
foreach my $ora_sid (keys(%database)) {
my $ora_home = $database{$ora_sid}{'ORA_HOME'};
unless (exists($versions{$ora_home})) {
$versions{$ora_home} = _getVersionAndBundle($ora_home);
}
my $version_bundle = $versions{$ora_home};
$database{$ora_sid}{'VERSION'} = $version_bundle->{'VERSION'};
$database{$ora_sid}{'BUNDLE'} = $version_bundle->{'BUNDLE'};
}
# Return complete database hash or only version and bundle, according to
# $versions_only argument
if ($versions_only) {
return \%versions;
} else {
return \%database;
}
}
# _getVersionAndBundle($ora_home)
#
# Simple method building a hash with two keys 'VERSION' and 'BUNDLE' and their
# values.
#
# Return: a hash reference
sub _getVersionAndBundle {
my $ora_home = shift;
my %version_bundle = (
'VERSION' => _getVersion($ora_home),
'BUNDLE' => _getBundle($ora_home)
);
return \%version_bundle;
}
# _getVersion($ora_home)
#
# Find Oracle server version installed in ORACLE_HOME.
#
# We are using the tnsping command for that.
# Return: the version string (for example "11.2.0.4.0" or "N/A" by default)
sub _getVersion {
my $ora_home = shift;
my $version = 'N/A';
my $tnsping = "$ora_home/bin/tnsping";
if (-x $tnsping) {
open(my $TNSPING_OUT, "$tnsping localhost |")
or die("Cannot exec tnsping $!");
while (my $tp_line = <$TNSPING_OUT>) {
if ($tp_line =~ m/^TNS Ping Utility for Linux: Version ([0-9.]+)/) {
$version = $1;
}
}
close($TNSPING_OUT);
}
return $version;
}
# _getBundle($ora_home)
#
# Find bundle version, reading a context.xml file down below ORACLE_HOME.
#
# Return: the full name of the install type (e.g. Standard or Enterprise) or,
# by default, "N/A"
sub _getBundle {
my $ora_home = shift;
my $bundle = 'N/A';
my $xml_re = qr/^\s*) {
if ($xml_line =~ $xml_re) {
$xml_line =~ $type_re;
my $abbr = $1;
$bundle = $bundles{$abbr} if exists($bundles{$abbr});
last;
}
}
close($CONTEXT_XML);
}
return $bundle;
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Modules/Download.pm 0000664 0000000 0000000 00000075773 14323200667 0023545 0 ustar 00root root 0000000 0000000 ###############################################################################
## OCSINVENTORY-NG
## Copyleft Pascal DANEK 2005
## Web : http://ocsinventory.sourceforge.net
##
## This code is open source and may be copied and modified as long as the source
## code is always made freely available.
## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
################################################################################
# Function by hook:
# -download_prolog_reader, download_message, download
# -download_inventory_handler
# -download_end_handler, begin, done, clean, finish, period, download, execute,
# check_signature and build_package
package Ocsinventory::Agent::Modules::Download;
use strict;
use Fcntl qw/:flock/;
use XML::Simple;
use LWP::UserAgent;
use Compress::Zlib;
use Digest::MD5;
use File::Path;
use Socket;
# Can be missing. By default, we use MD5
# You have to install it if you want to use SHA1 digest
eval{ require Digest::SHA1 };
#Global vars
my $ua;
my $download_config;
my @prior_pkgs;
sub new {
my $name="download"; #Set the name of your module here
my (undef,$context) = @_;
my $self = {};
# Create a special logger for the module
$self->{logger} = new Ocsinventory::Logger ({
config => $context->{config},
});
# We use the common object for the module
$self->{common} = $context->{common};
$self->{context} = $context;
$self->{logger}->{header}="[$name]";
$self->{structure} = {
name => $name,
start_handler => $name."_start_handler",
prolog_writer => undef,
prolog_reader => $name."_prolog_reader",
inventory_handler => $name."_inventory_handler",
end_handler => $name."_end_handler"
};
$self->{settings} = {
https_port => '443',
# Time to wait between scheduler periods, scheduling cycles and fragments downloads
frag_latency_default => 10,
period_latency_default => 0,
cycle_latency_default => 10,
max_error_count => 30,
# Number of loops for one period
period_lenght_default => 10,
};
$self->{messages} = {
# Errors
code_success => 'SUCCESS',
success_already_setup => 'SUCCESS_ALREADY_SETUP',
err_bad_id => 'ERR_BAD_ID',
err_download_info => 'ERR_DOWNLOAD_INFO',
err_bad_digest => 'ERR_BAD_DIGEST',
err_download_pack => 'ERR_DOWNLOAD_PACK',
err_build => 'ERR_BUILD',
err_execute => 'ERR_EXECUTE',
err_clean => 'ERR_CLEAN',
err_timeout => 'ERR_TIMEOUT',
};
# Special hash for packages
$self->{packages}= {};
bless $self;
}
sub download_start_handler {
my $self = shift;
my $logger = $self->{logger};
my $common = $self->{context}->{common};
my $config = $self->{context}->{config};
$logger->debug("Calling download_start_handler");
# Disabling module if local mode
if ($config->{stdout} || $config->{local}) {
$self->{disabled} = 1;
$logger->info("Agent is running in local mode...disabling module");
}
# If we cannot load prerequisite, we disable the module
if ($common->can_load('LWP')) {
my $lwp_version = $LWP::VERSION;
$lwp_version=$self->{common}->convertVersion($lwp_version,3);
if ($lwp_version > 583) { #Newer LWP version
unless ($common->can_load('LWP::Protocol::https')) {
$self->{disabled} = 1;
$logger->error("LWP::Protocol::https perl module is missing !!");
$logger->error("Humm my prerequisites are not OK...disabling module :( :(");
}
} else {
unless ($common->can_load('Crypt::SSLeay')) {
$self->{disabled} = 1;
$logger->error("Crypt::SSLeay perl module is missing !!");
$logger->error("Humm my prerequisites are not OK...disabling module :( :(");
}
}
} else {
$self->{disabled} = 1;
$logger->error("LWP perl module is missing !!");
$logger->error("Humm my prerequisites are not OK...disabling module :( :(");
}
}
sub download_prolog_reader{ #Read prolog response
my ($self,$prolog) = @_;
my $context = $self->{context};
my $logger = $self->{logger};
my $config = $self->{context}->{config};
my $network = $self->{context}->{network};
my $common = $self->{common};
my $settings = $self->{settings};
my $messages = $self->{messages};
my $packages = $self->{packages};
$logger->debug("Calling download_prolog_reader");
$logger->debug($prolog);
$prolog = XML::Simple::XMLin( $prolog, ForceArray => ['OPTION', 'PARAM']);
my $option;
# Create working directory
my $opt_dir = $context->{installpath}.'/download';
mkdir($opt_dir) unless -d $opt_dir;
# We create a file to tell to download process that we are running
open SUSPEND, ">$opt_dir/suspend";
close(SUSPEND);
# Create history file if needed
unless(-e "$opt_dir/history"){
open HISTORY, ">$opt_dir/history" or die("Cannot create history file: $!");
close(HISTORY);
}
# Create lock file if needed
unless(-e "$opt_dir/lock"){
open LOCK, ">$opt_dir/lock" or die("Cannot create lock file: $!");
close(LOCK);
}
# Retrieve our options
for $option (@{$prolog->{OPTION}}){
if ($option->{NAME} =~/download/i){
for (@{ $option->{PARAM} } ) {
# Type of param
if ($_->{'TYPE'} eq 'CONF'){
# Writing configuration
open CONFIG, ">$opt_dir/config" or die("Cannot open/create config file ($opt_dir/config)");
if (flock(CONFIG, LOCK_EX)){
$logger->debug("Writing config file.");
print CONFIG XMLout($_, RootName => 'CONF');
close(CONFIG);
$download_config = $_;
} else {
$logger->error("Cannot lock config file !!");
close(CONFIG);
return 0;
}
# Apply config
# ON ?
if ($_->{'ON'} == '0'){
$logger->info("Download is off.");
open LOCK, "$opt_dir/lock" or die("Cannot open lock file: $!");
if (flock(LOCK, LOCK_EX|LOCK_NB)){
close(LOCK);
unlink("$opt_dir/suspend");
return 0;
} else {
$logger->debug("Try to kill current download process...");
my $pid = ;
close(LOCK);
$logger->debug("Sending USR1 to $pid...");
if (kill("USR1", $pid)){
$logger->debug("Success.");
} else {
$logger->debug("Failed.");
}
return 0;
}
}
# Maybe a new package to download
} elsif ($_->{'TYPE'} eq 'PACK'){
$packages->{$_->{'ID'}} = {
'PACK_LOC' => $_->{'PACK_LOC'},
'INFO_LOC' => $_->{'INFO_LOC'},
#'ID' => $_->{'ID'},
'CERT_PATH' => $_->{'CERT_PATH'},
'CERT_FILE' => $_->{'CERT_FILE'},
'FORCE' => $_->{'FORCE'}
};
}
}
}
}
# We are now in download child
# Connect to server
if ($context->{network}) {
$ua = $context->{network}->{ua};
} else {
$logger->info("Cannot find network settings to make this module works properly...disabling module");
$self->{disabled} = 1;
}
# Check history file
unless(open HISTORY, "$opt_dir/history") {
flock(HISTORY, LOCK_EX);
unlink("$opt_dir/suspend");
$logger->error("Cannot read history file: $!");
return 1;
}
chomp(my @done = );
close(HISTORY);
# Package is maybe already handled
for (keys %$packages){
my $dir = $opt_dir."/".$_;
my $fileid = $_;
my $infofile = 'info';
my $location = $packages->{$_}->{'INFO_LOC'};
unless ($packages->{$_}->{'FORCE'} == 1) {
if($common->already_in_array($fileid, @done)){
$logger->info("Will not download $fileid. (already in history file)");
&download_message($fileid, $messages->{success_already_setup},$logger,$context);
next;
}
}
# Looking for packages status
unless(-d $dir){
$logger->debug("Making working directory for $fileid.");
mkdir($dir) or die("Cannot create $fileid directory: $!");
open FH, ">$dir/since" or die("Cannot create $fileid since file: $!");;
print FH time();
close(FH);
}
# Retrieve and writing info file if needed
unless(-f "$dir/$infofile"){
# Special value INSTALL_PATH
$packages->{$_}->{CERT_PATH} =~ s/INSTALL_PATH/$context->{installpath}/;
$packages->{$_}->{CERT_FILE} =~ s/INSTALL_PATH/$context->{installpath}/;
# Getting info file
if ($network->getFile("https","$location/$fileid","info","$dir/info")){
download_message($fileid, $self->{messages}->{err_download_info},$logger,$context);
$logger->error("Error download info file !!! Wrong URL or SSL certificate ?");
next;
}
}
}
unless(unlink("$opt_dir/suspend")){
$logger->error("Cannot delete suspend file: $!");
return 1;
}
return 0;
}
sub ssl_verify_callback {
my ($ok, $x509_store_ctx) = @_;
return $ok;
}
sub download_inventory_handler{ # Adding the ocs package ids to softwares
my ($self,$inventory) = @_;
my $context = $self->{context};
my $logger = $self->{logger};
$logger->debug("Calling download_inventory_handler");
my @history;
# Read download history file
if ( open PACKAGES, "$context->{installpath}/download/history" ){
flock(PACKAGES, LOCK_SH);
while(){
chomp( $_ );
push @history, { ID => $_ };
}
}
close(PACKAGES);
# Add it to inventory (will be handled by Download.pm server module
push @{ $inventory->{xmlroot}->{'CONTENT'}->{'DOWNLOAD'}->{'HISTORY'} },{
'PACKAGE'=> \@history
};
}
sub download_end_handler{ # Get global structure
my $self = shift;
my $context = $self->{context};
my $logger = $self->{logger};
my $common = $self->{common};
my $settings = $self->{settings};
my $messages = $self->{messages};
my $packages = $self->{packages};
$logger->debug("Calling download_end_handler");
my $dir = $context->{installpath}."/download";
my $pidfile = $dir."/lock";
return 0 unless -d $dir;
# We have jobs, we do it alone
my $fork = fork();
if ($fork>0){
return 0;
} elsif ($fork<0){
return 1;
} else {
$SIG{'USR1'} = sub {
print "Exiting on signal...\n";
&finish($logger, $context);
};
# Go into working directory
chdir($dir) or die("Cannot chdir to working directory...Abort\n");
}
# Maybe an other process is running
exit(0) if begin($pidfile,$logger);
# Retrieve the packages to download
opendir DIR, $dir or die("Cannot read working directory: $!");
my $end;
while(1){
# If agent is running, we wait
if (-e "suspend") {
$logger->debug('Found a suspend file... Will wait 10 seconds before retry');
sleep(10);
next;
}
$end = 1;
#TODO Uncomment this line #undef $packages;
# Reading configuration
open FH, "$dir/config";
if (flock(FH, LOCK_SH)){
$download_config = XMLin("$dir/config");
close(FH);
# If Frag latency is null, download is off
if ($download_config->{'ON'} eq '0'){
$logger->info("Option turned off. Exiting.");
finish($logger, $context);
}
} else {
close(FH);
if (-e "$dir/config") {
$logger->error("Cannot read config file :-( . Exiting.");
} else {
$logger->debug("Download not configured");
}
finish($logger, $context);
}
# Retrieving packages to download and their priority
while (my $entry = readdir(DIR)){
next if $entry !~ /^\d+$/;
next unless(-d $entry);
# Clean package if info file does not still exist
unless(-e "$entry/info"){
$logger->debug("No info file found for $entry!!");
clean( $entry, $logger, $context, $messages, $packages );
next;
}
my $info = XML::Simple::XMLin( "$entry/info" ) or next;
# Check that fileid == directory name
if ($info->{'ID'} ne $entry){
$logger->debug("ID in info file does not correspond!!");
clean( $entry, $logger, $context, $messages, $packages );
download_message($entry, $messages->{err_bad_id},$logger,$context);
next;
}
# Manage package timeout
# Clean package if since timestamp is not present
unless(-e "$entry/since"){
$logger->debug("No since file found!!");
clean($entry, $logger, $context,$messages,$packages );
next;
} else {
my $time = time();
if (open SINCE, "$entry/since"){
my $since = ;
if ($since=~/\d+/){
if ((($time-$since)/86400) > $download_config->{TIMEOUT}){
$logger->error("Timeout Reached for $entry.");
clean($entry, $logger, $context,$messages,$packages );
&download_message($entry, $messages->{err_timeout},$logger,$context);
close(SINCE);
next;
} else {
$logger->debug("Checking timeout for $entry... OK");
}
} else {
$logger->error("Since data for $entry is incorrect.");
clean($entry, $logger, $context, $messages, $packages );
&download_message($entry, $messages->{err_timeout},$logger,$context);
close(SINCE);
next;
}
close(SINCE);
} else {
$logger->error("Cannot find since data for $entry.");
clean($entry, $logger, $context, $messages, $packages );
&download_message($entry, $messages->{err_timeout},$logger,$context);
next;
}
}
# Building task file if needed
unless( -f "$entry/task" and -f "$entry/task_done" ){
open FH, ">$entry/task" or die("Cannot create task file for $entry: $!");
my $i;
my $frags = $info->{'FRAGS'};
# There are no frags if there is only a command
if ($frags){
for ($i=1;$i<=$frags;$i++){
print FH "$entry-$i\n";
}
};
close FH;
# To be sure that task file is fully created
open FLAG, ">$entry/task_done" or die ("Cannot create task flag file for $entry: $!");
close(FLAG);
}
# Store info XML descriptions in package attributes
for (keys %$info){
$packages->{$entry}->{$_} = $info->{$_}
}
$end = 0;
}
# Rewind directory
rewinddir(DIR);
# Call packages scheduler
if ($end){
last;
} else {
period($packages,$logger,$context,$self->{messages},$settings);
}
}
$logger->info("No more package to download.");
finish($logger, $context);
}
# Schedule the packages
sub period{
my ($packages,$logger,$context,$messages,$settings) = @_ ;
my $period_lenght_default = $settings->{period_lenght_default} ;
my $frag_latency_default= $settings->{frag_latency_default} ;
my $cycle_latency_default= $settings->{cycle_latency_default} ;
my $period_latency_default= $settings->{period_latency_default} ;
my $i;
#Serching packages with the priority 0
for (keys %$packages) {
if ($packages->{$_}->{'PRI'} eq "0") {
push (@prior_pkgs,$_);
}
}
$logger->debug("New period. Nb of cycles: ".
(defined($download_config->{'PERIOD_LENGTH'})?$download_config->{'PERIOD_LENGTH'}:$period_lenght_default));
for ($i=1;$i<=( defined($download_config->{'PERIOD_LENGTH'})?$download_config->{'PERIOD_LENGTH'}:$period_lenght_default);$i++){
# Highest priority
if (@prior_pkgs){
$logger->debug("Managing ".scalar(@prior_pkgs)." package(s) with absolute priority.");
for (@prior_pkgs){
# If done file found, clean package
if (-e "$_/done"){
$logger->debug("done file found!!");
done($_,$logger,$context,$messages,$settings,$packages);
next;
}
download($_,$logger,$context,$messages,$settings,$packages);
$logger->debug("Now pausing for a fragment latency => ".(
defined($download_config->{'FRAG_LATENCY'})?$download_config->{'FRAG_LATENCY'}:$frag_latency_default)
." seconds");
sleep( defined($download_config->{'FRAG_LATENCY'})?$download_config->{'FRAG_LATENCY'}:$frag_latency_default );
}
next;
}
# Normal priority
for (keys %$packages){
# If done file found, clean package
if(-e "$_/done"){
$logger->debug("done file found!!");
done($_,$logger,$context,$messages,$settings,$packages);
next;
}
next if $i % $packages->{$_}->{'PRI'} != 0;
download($_,$logger,$context,$messages,$settings,$packages);
$logger->debug("Now pausing for a fragment latency => ".
(defined( $download_config->{'FRAG_LATENCY'} )?$download_config->{'FRAG_LATENCY'}:$frag_latency_default)
." seconds");
sleep(defined($download_config->{'FRAG_LATENCY'})?$download_config->{'FRAG_LATENCY'}:$frag_latency_default);
}
$logger->debug("Now pausing for a cycle latency => ".(
defined($download_config->{'CYCLE_LATENCY'})?$download_config->{'CYCLE_LATENCY'}:$cycle_latency_default)
." seconds");
sleep(defined($download_config->{'CYCLE_LATENCY'})?$download_config->{'CYCLE_LATENCY'}:$cycle_latency_default);
}
sleep($download_config->{'PERIOD_LATENCY'}?$download_config->{'PERIOD_LATENCY'}:$period_latency_default);
}
# Download a fragment of the specified package
sub download {
my ($id,$logger,$context,$messages,$settings,$packages) = @_;
my $error;
my $proto = $packages->{$id}->{'PROTO'};
my $location = $packages->{$id}->{'PACK_LOC'};
my $network = $context->{network};
# If we find a temp file, we know that the update of the task file has failed for any reason. So we retrieve it from this file
if (-e "$id/task.temp") {
unlink("$id/task.temp");
rename("$id/task.temp","$id/task") or return 1;
}
# Retrieve fragments already downloaded
unless(open TASK, "$id/task"){
$logger->error("Cannot open $id/task.");
return 1;
}
my @task = ;
# Done
if (!@task){
$logger->debug("Download of $id... Finished.");
close(TASK);
execute($id,$logger,$context,$messages,$settings,$packages);
return 0;
}
my $fragment = shift(@task);
$logger->debug("Downloading $fragment...");
# Using proxy if possible
my $res = $network->getFile(lc($proto),"$location/$id",$fragment,"$id/$fragment");
# Checking if connected
unless($res) {
#Success
$error = 0;
# Updating task file
rename(">$id/task", ">$id/task.temp");
open TASK, ">$id/task" or return 1;
print TASK @task;
close(TASK);
unlink(">$id/task.temp");
} else {
$error++;
if ($error > $settings->{max_error_count}){
$logger->error("Error : Max errors count reached");
finish($logger,$context);
}
return 1;
}
return 0;
}
# Assemble and handle downloaded package
sub execute{
my ($id,$logger,$context,$messages,$settings,$packages) = @_;
my $common = $context->{common};
my $tmp = $id."/tmp";
my $exit_code;
$logger->debug("Execute orders for package $id.");
if (build_package($id,$logger,$context,$messages,$packages)){
clean($id,$logger, $context,$messages,$packages);
return 1;
} else {
# First, we get in temp directory
unless( chdir($tmp) ){
$logger->error("Cannot chdir to working directory: $!");
download_message($id, $messages->{err_execute}, $logger,$context);
clean($id,$logger, $context,$messages,$packages);
return 1;
}
# Executing preorders (notify user, auto launch, etc....
# $id->{NOTIFY_USER}
# $id->{NOTIFY_TEXT}
# $id->{NOTIFY_COUNTDOWN}
# $id->{NOTIFY_CAN_ABORT}
# TODO: notification to send through DBUS to the user
eval{
# Execute instructions
if ($packages->{$id}->{'ACT'} eq 'LAUNCH'){
my $exe_line = $packages->{$id}->{'NAME'};
$packages->{$id}->{'NAME'} =~ s/^([^ -]+).*/$1/;
# Exec specified file (LAUNCH => NAME)
if (-e $packages->{$id}->{'NAME'}){
$logger->debug("Launching $packages->{$id}->{'NAME'}...");
chmod(0755, $packages->{$id}->{'NAME'}) or die("Cannot chmod: $!");
$exit_code = system( "./".$exe_line ) >> 8;
} else {
die();
}
} elsif ($packages->{$id}->{'ACT'} eq 'EXECUTE'){
# Exec specified command EXECUTE => COMMAND
$logger->debug("Execute $packages->{$id}->{'COMMAND'}...");
system( $packages->{$id}->{'COMMAND'} ) and die();
} elsif ($packages->{$id}->{'ACT'} eq 'STORE'){
# Store files in specified path STORE => PATH
$packages->{$id}->{'PATH'} =~ s/INSTALL_PATH/$context->{installpath}/;
# Build it if needed
my @dir = split('/', $packages->{$id}->{'PATH'});
my $dir;
for (@dir){
$dir .= "$_/";
unless(-e $dir){
mkdir($dir);
$logger->debug("Create $dir...");
}
}
$logger->debug("Storing package to $packages->{$id}->{'PATH'}...");
# Stefano Brandimarte => Stevenson!
system($common->get_path('cp')." -pr * ".$packages->{$id}->{'PATH'}) and die();
}
};
if ($@){
# Notify success to ocs server
download_message($id, $messages->{err_execute},$logger,$context);
chdir("../..") or die("Cannot go back to download directory: $!");
clean($id,$logger,$context,$messages,$packages);
return 1;
} else {
chdir("../..") or die("Cannot go back to download directory: $!");
done($id,$logger,$context,$messages,$settings,$packages,(defined($exit_code)?$exit_code:'_NONE_'));
return 0;
}
}
}
# Check package integrity
sub build_package{
my ($id,$logger,$context,$messages,$packages) = @_;
my $common = $context->{common};
my $count = $packages->{$id}->{'FRAGS'};
my $i;
my $tmp = "./$id/tmp";
unless(-d $tmp){
mkdir("$tmp");
}
# No job if no files
return 0 unless $count;
# Assemble package
$logger->info("Building package for $id.");
for ($i=1;$i<=$count;$i++){
if (-f "./$id/$id-$i"){
# We make a tmp working directory
if ($i==1){
open PACKAGE, ">$tmp/build.tar.gz" or return 1;
}
# We write each fragment in the final package
open FRAGMENT, "./$id/$id-$i" or return 1;
my $row;
while ($row = ){
print PACKAGE $row;
}
close(FRAGMENT);
} else {
return 1;
}
}
close(PACKAGE);
#
if (check_signature($packages->{$id}->{'DIGEST'}, "$tmp/build.tar.gz", $packages->{$id}->{'DIGEST_ALGO'}, $packages->{$id}->{'DIGEST_ENCODE'},$logger)){
download_message($id, $messages->{err_bad_digest},$logger,$context);
return 1;
}
if ( system( $common->get_path("tar")." -xvzf $tmp/build.tar.gz -C $tmp") ){
$logger->error("Cannot extract $id with tar, trying with unzip.");
if ( system( $common->get_path("unzip")." $tmp/build.tar.gz -d $tmp") ){
$logger->error("Cannot extract $id with unzip.");
download_message($id,$messages->{err_build},$logger,$context);
return 1;
}
}
$logger->debug("Building of $id... Success.");
unlink("$tmp/build.tar.gz") or die ("Cannot remove build file: $!\n");
return 0;
}
sub check_signature{
my ($checksum, $file, $digest, $encode,$logger) = @_;
$logger->info("Checking signature for $file.");
my $base64;
# Open file
unless(open FILE, $file){
$logger->error("cannot open $file: $!");
return 1;
}
binmode(FILE);
# Retrieving encoding form
if ($encode =~ /base64/i){
$base64 = 1;
$logger->debug('Digest format: Base 64');
} elsif ($encode =~ /hexa/i){
$logger->debug('Digest format: Hexadecimal');
} else {
$logger->debug('Digest format: Not supported');
return 1;
}
eval{
# Check it
if ($digest eq 'MD5'){
$logger->debug('Digest algo: MD5');
if ($base64){
die unless Digest::MD5->new->addfile(*FILE)->b64digest eq $checksum;
} else {
die unless Digest::MD5->new->addfile(*FILE)->hexdigest eq $checksum;
}
} elsif ($digest eq 'SHA1'){
$logger->debug('Digest algo: SHA1');
if ($base64){
die unless Digest::SHA1->new->addfile(*FILE)->b64digest eq $checksum;
} else {
die unless Digest::SHA1->new->addfile(*FILE)->hexdigest eq $checksum;
}
} else {
$logger->debug('Digest algo unknown: '.$digest);
die;
}
};
if ($@){
$logger->debug("Digest checking error !!");
close(FILE);
return 1;
} else {
close(FILE);
$logger->debug("Digest OK...");
return 0;
}
}
# Launch a download error to ocs server
sub download_message{
my ($id, $code,$logger,$context) = @_;
$logger->debug("Sending message for $id, code=$code.");
my $xml = {
'DEVICEID' => $context->{deviceid},
'QUERY' => 'DOWNLOAD',
'ID' => $id,
'ERR' => $code
};
# Generate xml
$xml = XMLout($xml, RootName => 'REQUEST');
# Compress data
$xml = Compress::Zlib::compress( $xml );
my $URI = $context->{servername};
# Send request
my $request = HTTP::Request->new(POST => $URI);
$request->header('Pragma' => 'no-cache', 'Content-type', 'application/x-compress');
$request->content($xml);
my $res = $ua->request($request);
# Checking result
if ($res->is_success) {
return 0;
}else{
return 1;
}
}
# At the beginning of end handler
sub begin{
my ($pidfile,$logger) = @_;
open LOCK_R, "$pidfile" or die("Cannot open pid file: $!");
if (flock(LOCK_R,LOCK_EX|LOCK_NB)){
open LOCK_W, ">$pidfile" or die("Cannot open pid file: $!");
select(LOCK_W) and $|=1;
select(STDOUT) and $|=1;
print LOCK_W $$;
$logger->info("Beginning work. I am $$.");
return 0;
} else {
close(LOCK_R);
$logger->error("$pidfile locked. Cannot begin work... :-(");
return 1;
}
}
sub done{
my ($id,$logger,$context,$messages,$settings,$packages,$suffix) = @_;
my $common = $context->{common};
my $frag_latency_default = $settings->{frag_latency_default};
$logger->debug("Package $id... Done. Sending message...");
# Trace installed package
open DONE, ">$id/done";
close(DONE);
# Read history file
open HISTORY,"$context->{installpath}/download/history" or warn("Cannot open history file: $!");
chomp(my @historyIds = );
close(HISTORY);
# Put it in history file
open HISTORY,">>$context->{installpath}/download/history" or warn("Cannot open history file: $!");
flock(HISTORY, LOCK_EX);
if ( $common->already_in_array($id, @historyIds) ){
$logger->debug("Warning: ID $id has been found in the history file (package was already deployed)");
} else {
$logger->debug("Writing $id reference in history file");
print HISTORY $id,"\n";
}
close(HISTORY);
# Notify success to ocs server
my $code;
if ($suffix ne '_NONE_'){
$code = $messages->{code_success}."_$suffix";
} else {
$code = $messages->{code_success};
}
unless(download_message($id, $code,$logger,$context)){
clean($id,$logger,$context,$messages,$packages);
} else {
sleep( defined($download_config->{'FRAG_LATENCY'})?$download_config->{'FRAG_LATENCY'}:$frag_latency_default );
}
return 0;
}
sub clean{
my ($id,$logger,$context,$messages,$packages) = @_;
$logger->info("Cleaning $id package.");
delete $packages->{$id};
#If the package is priority 0
if ((my $index) = grep { $prior_pkgs[$_] eq $id } 0..$#prior_pkgs){
delete $prior_pkgs[$index];
}
unless(File::Path::rmtree($id, 0)){
$logger->error("Cannot clean $id!! Abort...");
download_message($id, $messages->{err_clean},$logger,$context);
die();
}
return 0;
}
# At the end
sub finish{
my ($logger,$context) = @_;
open LOCK, '>'.$context->{installpath}.'/download/lock';
$logger->debug("End of work...\n");
exit(0);
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Modules/Example.pm 0000664 0000000 0000000 00000005260 14323200667 0023351 0 ustar 00root root 0000000 0000000 ###############################################################################
## OCSINVENTORY-NG
## Copyleft Guillaume PROTET 2010
## Web : http://www.ocsinventory-ng.org
##
## This code is open source and may be copied and modified as long as the source
## code is always made freely available.
## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
################################################################################
package Ocsinventory::Agent::Modules::Example;
sub new {
my $name="example"; #Set the name of your module here
my (undef,$context) = @_;
my $self = {};
#Create a special logger for the module
$self->{logger} = new Ocsinventory::Logger ({
config => $context->{config}
});
$self->{logger}->{header}="[$name]";
$self->{context}=$context;
$self->{structure}= {
name => $name,
start_handler => $name."_start_handler", #or undef if don't use this hook
prolog_writer => $name."_prolog_writer", #or undef if don't use this hook
prolog_reader => $name."_prolog_reader", #or undef if don't use this hook
inventory_handler => $name."_inventory_handler", #or undef if don't use this hook
end_handler => $name."_end_handler" #or undef if don't use this hook
};
bless $self;
}
######### Hook methods ############
sub example_start_handler { #Use this hook to test prerequisites needed by module and disble it if needed
my $self = shift;
my $logger = $self->{logger};
$logger->debug("Yeah you are in example_start_handler :)");
my $prerequisites = 1 ;
if ( $prerequisites == 0 ) {
$self->{disabled} = 1; #Use this to disable the module
$logger->debug("Humm my prerequisites are not OK...disabling module :( :( ");
}
}
sub example_prolog_writer { #Use this hook to add information the prolog XML
my $self = shift;
my $logger = $self->{logger};
$logger->debug("Yeah you are in example_prolog_writer :)");
}
sub example_prolog_reader { #Use this hook to read the answer from OCS server
my $self = shift;
my $logger = $self->{logger};
$logger->debug("Yeah you are in example_prolog_reader :)");
}
sub example_inventory_handler { #Use this hook to add or modify entries in the inventory XML
my $self = shift;
my $logger = $self->{logger};
$logger->debug("Yeah you are in example_inventory_handler :)");
}
sub example_end_handler { #Use this hook to add treatments before the end of agent launch
my $self = shift;
my $logger = $self->{logger};
$logger->debug("Yeah you are in example_end_handler :)");
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Modules/SnmpScan.pm 0000664 0000000 0000000 00000042627 14323200667 0023510 0 ustar 00root root 0000000 0000000 ###############################################################################
## OCSINVENTORY-NG
## Copyleft Guillaume PROTET 2010
## Web : http://www.ocsinventory-ng.org
##
## This code is open source and may be copied and modified as long as the source
## code is always made freely available.
## Please refer to the General Public Licence http://www.gnu.org/ or Licence.txt
################################################################################
package Ocsinventory::Agent::Modules::SnmpScan;
use strict;
no strict 'refs';
no strict 'subs';
use warnings;
use XML::Simple;
use Digest::MD5;
sub new {
my $name="snmpscan"; #Set the name of your module here
my (undef,$context) = @_;
my $self = {};
#Create a special logger for the module
$self->{logger} = new Ocsinventory::Logger ({
config => $context->{config}
});
$self->{logger}->{header}="[$name]";
$self->{common} = $context->{common};
$self->{context}=$context;
$self->{structure}= {
name => $name,
start_handler => $name."_start_handler",
prolog_writer => undef,
prolog_reader => $name."_prolog_reader",
inventory_handler => undef,
end_handler => $name."_end_handler",
};
# We create a xml for the snmp inventory that we will be sent to server
$self->{inventory}={};
bless $self;
}
sub snmpscan_start_handler {
my $self = shift;
my $logger = $self->{logger};
my $common = $self->{context}->{common};
my $config = $self->{context}->{config};
$logger->debug("Calling snmp_start_handler");
# Disabling module if local mode
if ($config->{stdout} || $config->{local}) {
$self->{disabled} = 1;
$logger->info("Agent is running in local mode...disabling module");
}
# If we cannot load prerequisite, we disable the module
unless ($common->can_load('Net::SNMP')) {
$self->{disabled} = 1;
$logger->error("Net::SNMP perl module is missing !!");
$logger->error("Humm my prerequisites are not OK...disabling module :( :(");
}
}
sub snmpscan_prolog_reader {
my ($self, $prolog) = @_;
my $logger = $self->{logger};
my $network = $self->{context}->{network};
my $option;
$logger->debug("Calling snmp_prolog_reader");
$prolog = XML::Simple::XMLin( $prolog, ForceArray => ['OPTION', 'PARAM']);
for $option (@{$prolog->{OPTION}}){
if ($option->{NAME} =~/snmp/i){
$self->{doscans} = 1 ;
for ( @{ $option->{PARAM} } ) {
if ($_->{'TYPE'} eq 'DEVICE'){
# Adding the IP in the devices array
push @{$self->{netdevices}},{
IPADDR => $_->{IPADDR},
MACADDR => $_->{MACADDR},
};
}
if ($_->{'TYPE'} eq 'COMMUNITY'){
# Adding the community in the communities array
push @{$self->{communities}},{
VERSION=>$_->{VERSION},
NAME=>$_->{NAME},
USERNAME=>$_->{USERNAME},
AUTHPROTO=>$_->{AUTHPROTO},
AUTHPASSWD=>$_->{AUTHPASSWD},
PRIVPROTO=>$_->{PRIVPROTO},
PRIVPASSWD=>$_->{PRIVPASSWD},
LEVEL=>$_->{LEVEL}
};
}
if ($_->{'TYPE'} eq 'NETWORK'){
push @{$self->{nets_to_scan}},$_->{SUBNET};
}
if ($_->{'TYPE'} eq 'SNMP_TYPE'){
if($_->{TABLE_TYPE_NAME} ne 'snmp_default') {
push @{$self->{snmp_type_condition}},{
TABLE_TYPE_NAME => $_->{TABLE_TYPE_NAME},
CONDITION_OID => $_->{CONDITION_OID},
CONDITION_VALUE => $_->{CONDITION_VALUE}
};
} else {
push @{$self->{snmp_type_condition_default}},{
TABLE_TYPE_NAME => $_->{TABLE_TYPE_NAME},
CONDITION_OID => $_->{CONDITION_OID}
};
}
push @{$self->{snmp_type_infos}},{
TABLE_TYPE_NAME => $_->{TABLE_TYPE_NAME},
LABEL_NAME => $_->{LABEL_NAME},
OID => $_->{OID}
};
}
}
}
}
}
sub snmpscan_end_handler {
my $self = shift;
my $logger = $self->{logger};
my $common = $self->{context}->{common};
my $network = $self->{context}->{network};
$logger->debug("Calling snmp_end_handler");
# If no order form server
return unless $self->{doscans};
# Flushing xmltags if it has not been done
$common->flushXMLTags();
# We get the config
my $config = $self->{context}->{config};
# Load setting from the config file
my $configagent = new Ocsinventory::Agent::Config;
$configagent->loadUserParams();
my $communities=$self->{communities};
if ( ! defined ($communities ) ) {
$logger->debug("We have no Community from server, we use default public community");
$communities=[{VERSION=>"2c",NAME=>"public"}];
}
my ($name,$comm,$error,$system_oid);
# Initalising the XML properties
my $snmp_inventory = $self->{inventory};
$snmp_inventory->{xmlroot}->{QUERY} = ['SNMP'];
$snmp_inventory->{xmlroot}->{DEVICEID} = [$self->{context}->{config}->{deviceid}];
# Scanning network
$logger->debug("Snmp: Scanning network");
my $nets_to_scan=$self->{nets_to_scan};
foreach my $net_to_scan ( @$nets_to_scan ){
$self->snmp_ip_scan($net_to_scan);
}
$logger->debug("Snmp: Ending Scanning network");
# Begin scanning ip tables
my $ip=$self->{netdevices};
foreach my $device ( @$ip ) {
my $session = undef;
my $oid_condition = undef;
my $devicedata = $common->{xmltags}; #To fill the xml informations for this device
my $snmp_table = undef;
my $snmp_condition_oid = undef;
my $snmp_condition_value = undef;
my $regex = undef;
$logger->debug("Scanning $device->{IPADDR} device");
# Search for the good snmp community in the table community
LIST_SNMP: foreach $comm ( @$communities ) {
# Test if we use SNMP v3
if ( $comm->{VERSION} eq "3" ) {
if($comm->{LEVEL} eq '' || $comm->{LEVEL} eq 'noAuthNoPriv') {
($session, $error) = Net::SNMP->session(
-retries => $configagent->{config}{snmpretry}, # SNMP retry in config file
-timeout => $configagent->{config}{snmptimeout}, # SNMP Timeout in config file
-version => 'snmpv'.$comm->{VERSION},
-hostname => $device->{IPADDR},
-translate => [-nosuchinstance => 0, -nosuchobject => 0, -octetstring => 0],
-username => $comm->{USERNAME}
);
}
if($comm->{LEVEL} eq 'authNoPriv') {
if($comm->{AUTHPROTO} eq '') {
$comm->{AUTHPROTO} = "md5";
}
($session, $error) = Net::SNMP->session(
-retries => $configagent->{config}{snmpretry}, # SNMP retry in config file
-timeout => $configagent->{config}{snmptimeout}, # SNMP Timeout in config file
-version => 'snmpv'.$comm->{VERSION},
-hostname => $device->{IPADDR},
-translate => [-nosuchinstance => 0, -nosuchobject => 0, -octetstring => 0],
-username => $comm->{USERNAME},
-authprotocol => $comm->{AUTHPROTO},
-authpassword => $comm->{AUTHPASSWD}
);
}
if($comm->{LEVEL} eq 'authPriv') {
if($comm->{AUTHPROTO} eq '') {
$comm->{AUTHPROTO} = "md5";
}
if($comm->{PRIVPROTO} eq '') {
$comm->{PRIVPROTO} = "des";
}
($session, $error) = Net::SNMP->session(
-retries => $configagent->{config}{snmpretry}, # SNMP retry in config file
-timeout => $configagent->{config}{snmptimeout}, # SNMP Timeout in config file
-version => 'snmpv'.$comm->{VERSION},
-hostname => $device->{IPADDR},
-translate => [-nosuchinstance => 0, -nosuchobject => 0, -octetstring => 0],
-username => $comm->{USERNAME},
-authprotocol => $comm->{AUTHPROTO},
-authpassword => $comm->{AUTHPASSWD},
-privpassword => $comm->{PRIVPASSWD},
-privprotocol => $comm->{PRIVPROTO}
);
}
# For a use in constructor module (Cisco)
$self->{username}=$comm->{USERNAME};
$self->{authpassword}=$comm->{AUTHPASSWD};
$self->{authprotocol}=$comm->{AUTHPROTO};
$self->{privpassword}=$comm->{PRIVPASSWD};
$self->{privprotocol}= $comm->{PRIVPROTO};
} else {
# We have an older version v2c ou v1
($session, $error) = Net::SNMP->session(
-retries => $configagent->{config}{snmpretry}, # SNMP retry in config file
-timeout => $configagent->{config}{snmptimeout}, # SNMP Timeout in config file
-version => 'snmpv'.$comm->{VERSION},
-hostname => $device->{IPADDR},
-community => $comm->{NAME},
-translate => [-nosuchinstance => 0, -nosuchobject => 0, -octetstring => 0],
);
};
unless (defined($session)) {
$logger->error("Snmp INFO: $error");
} else {
$self->{snmp_session}=$session;
# For a use in constructor module (Cisco)
$self->{snmp_community}=$comm->{NAME};
$self->{snmp_version}=$comm->{VERSION};
my $snmp_key = $self->{snmp_type_condition};
my $snmp_key_default = $self->{snmp_type_condition_default};
LIST_TYPE: foreach my $snmp_value (@$snmp_key) {
$oid_condition = $session->get_request(-varbindlist => [$snmp_value->{CONDITION_OID}]);
$snmp_table = $snmp_value->{TABLE_TYPE_NAME};
$snmp_condition_oid = $snmp_value->{CONDITION_OID};
$snmp_condition_value = $snmp_value->{CONDITION_VALUE};
$regex = $self->regex($snmp_condition_value);
last LIST_TYPE if (defined $oid_condition && ($oid_condition->{$snmp_value->{CONDITION_OID}} eq $snmp_value->{CONDITION_VALUE} || $oid_condition->{$snmp_value->{CONDITION_OID}} =~ /$regex/));
}
last LIST_SNMP if (defined $oid_condition && ($oid_condition->{$snmp_condition_oid} eq $snmp_condition_value || $oid_condition->{$snmp_condition_oid} =~ /$regex/));
LIST_TYPE: foreach my $snmp_value_default (@$snmp_key_default) {
$oid_condition = $session->get_request(-varbindlist => [$snmp_value_default->{CONDITION_OID}]);
$snmp_table = $snmp_value_default->{TABLE_TYPE_NAME};
$snmp_condition_oid = $snmp_value_default->{CONDITION_OID};
last LIST_TYPE if (defined $oid_condition);
}
last LIST_SNMP if (defined $oid_condition && $snmp_table eq 'snmp_default');
$session->close;
$self->{snmp_session}=undef;
}
}
if (defined $oid_condition) {
my $xmltags = $common->{xmltags};
$session->max_msg_size(8192);
# We have found the good Community, we can scan this equipment
# We indicate that we scan a new equipment
$self->{number_scan}++;
my $data;
my $snmp_infos = $self->{snmp_type_infos};
foreach my $datas (@$snmp_infos) {
my $data_value = undef;
if($datas->{TABLE_TYPE_NAME} eq $snmp_table) {
$data = $session->get_request(-varbindlist => [$datas->{OID}]);
$data_value = $data->{$datas->{OID}};
if(defined $data_value && $data_value =~ m/([\x{0}-\x{9}]|[\x{B}-\x{C}]|[\x{E}-\x{1F}]|[\x{7F}-\x{FF}])/) {
$data_value = unpack "H*", $data_value;
$data_value = substr $data_value, 2;
my @split = unpack '(A2)*', $data_value;
$data_value = uc(join ':', @split);
}
if(!defined $data_value || $data_value eq '') {
my @table;
$data = $session->get_table(-baseoid => $datas->{OID});
foreach my $key (keys %{$data}) {
if(defined $data->{$key} && $data->{$key} =~ m/([\x{0}-\x{9}]|[\x{B}-\x{C}]|[\x{E}-\x{1F}]|[\x{7F}-\x{FF}])/) {
$data->{$key} = unpack "H*", $data->{$key};
$data->{$key} = substr $data->{$key}, 2;
my @split = unpack '(A2)*', $data->{$key};
$data->{$key} = uc(join ':', @split);
}
push @table, $data->{$key};
}
$data_value = join ' - ', @table;
}
$xmltags->{$datas->{LABEL_NAME}}[0] = $data_value;
}
}
push @{$snmp_inventory->{xmlroot}->{CONTENT}->{$snmp_table}},$xmltags;
# We have finished with this equipment
if (defined $session) {
$session->close;
}
$self->{snmp_session}=undef;
# We clear the xml data for this device
$common->flushXMLTags();
}
}
$logger->info("No more SNMP device to scan");
# Formatting the XML and sendig it to the server
my $content = XMLout( $snmp_inventory->{xmlroot}, RootName => 'REQUEST' , XMLDecl => '', SuppressEmpty => undef );
#Cleaning XML to delete unprintable characters
my $clean_content = $common->cleanXml($content);
$network->sendXML({message => $clean_content});
$logger->debug("End snmp_end_handler :)");
}
sub snmp_ip_scan {
my ($self,$net_to_scan) = @_;
my $logger=$self->{logger};
my $common=$self->{common};
if ($common->can_load('Net::Netmask') ) {
my $block=Net::Netmask->new($net_to_scan);
my $size=$block->size()-2;
my $index=1;
if ( $common->can_run('nmap') && $common->can_load('Nmap::Parser') ) {
$logger->debug("Scannig $net_to_scan with nmap");
my $nmaparser = Nmap::Parser->new;
$nmaparser->parsescan("nmap","-sn",$net_to_scan);
for my $host ($nmaparser->all_hosts("up")) {
my $res=$host->addr;
$logger->debug("Found $res");
push( @{$self->{netdevices}},{ IPADDR=>$res }) unless $self->search_netdevice($res);
}
} elsif ($common->can_load('Net::Ping')) {
$logger->debug("Scanning $net_to_scan with ping");
my $ping=Net::Ping->new("icmp",1);
while ($index <= $size) {
my $res=$block->nth($index);
if ($ping->ping($res)) {
$logger->debug("Found $res");
push( @{$self->{netdevices}},{ IPADDR=>$res }) unless $self->search_netdevice($res);
}
$index++;
}
$ping->close();
} else {
$logger->debug("No scan possible");
}
} else {
$logger->debug("Net::Netmask not present: no scan possible");
}
}
sub search_netdevice {
my ($self,$ip)= @_ ;
for (@{$self->{netdevices}}) {
if ($ip =~ /^$_->{IPADDR}$/) {
return 1;
}
}
}
sub regex {
my ($self,$regex) = @_;
if(($regex !~ m/\*/)){
$regex = "\^".$regex."\$";
}
if((substr( $regex, -1) eq '*') && (substr( $regex, 0, 1) eq '*')){
$regex = $regex =~ s/\*//gr;
}
if((substr( $regex, 0, 1 ) eq '*') && (substr( $regex, -1) ne '*')){
$regex = $regex =~ s/\*//gr;
$regex = $regex."\$";
}
if((substr( $regex, -1) eq '*') && (substr( $regex, 0, 1) ne '*')){
$regex = $regex =~ s/\*//gr;
$regex = "\^".$regex;
}
return $regex;
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/Network.pm 0000664 0000000 0000000 00000012434 14323200667 0022000 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::Network;
# TODO:
# - set the correct deviceID and olddeviceID
use strict;
use warnings;
use IO::Socket::SSL qw(SSL_VERIFY_NONE);
use LWP::UserAgent;
use Socket;
use Ocsinventory::Compress;
use Ocsinventory::Agent::Encrypt;
#$XML::Simple::PREFERRED_PARSER = 'XML::Parser';
sub new {
my (undef, $params) = @_;
my $self = {};
$self->{accountconfig} = $params->{accountconfig};
$self->{accountinfo} = $params->{accountinfo};
$self->{common} = $params->{common};
my $logger = $self->{logger} = $params->{logger};
$self->{config} = $params->{config};
my $uaserver;
if ($self->{config}->{server} =~ /^http(|s):\/\//) {
$self->{URI} = $self->{config}->{server};
$uaserver = $self->{config}->{server};
$uaserver =~ s/^http(|s):\/\///;
$uaserver =~ s/\/.*//;
if ($uaserver !~ /:\d+$/) {
$uaserver .= ':443' if $self->{config}->{server} =~ /^https:/;
$uaserver .= ':80' if $self->{config}->{server} =~ /^http:/;
}
} else {
$self->{URI} = "http://".$self->{config}->{server}.$self->{config}->{remotedir};
$uaserver = $self->{config}->{server};
}
$self->{compress} = new Ocsinventory::Compress ({logger => $logger});
# Connect to server
$self->{ua} = LWP::UserAgent->new(keep_alive => 1);
if ($self->{config}->{proxy}) {
$self->{ua}->proxy(['http', 'https'], 'connect://'.$self->{config}->{proxy}.'');
} else {
$self->{ua}->env_proxy;
}
my $version = 'OCS-NG_unified_unix_agent_v';
$version .= exists ($self->{config}->{version})?$self->{config}->{version}:'';
my $userencrypt = Ocsinventory::Agent::Encrypt::getClearText($self->{config}->{user});
my $pwdencrypt = Ocsinventory::Agent::Encrypt::getClearText($self->{config}->{password});
$self->{ua}->agent($version);
$self->{ua}->credentials(
$uaserver, # server:port, port is needed
$self->{config}->{realm},
$userencrypt,
$pwdencrypt
);
#Setting SSL configuration depending on LWP version
$self->{ua}->_agent =~ /^libwww-perl\/(.*)$/;
my $lwp_version= $1;
$lwp_version=$self->{common}->convertVersion($lwp_version,3);
if ($lwp_version > 583) {
$self->{ua}->ssl_opts(
verify_hostname => $self->{config}->{ssl},
SSL_ca_file => $self->{config}->{ca}
);
if ($self->{config}->{ssl} == 0 ) {
$self->{ua}->ssl_opts(
SSL_verify_mode => SSL_VERIFY_NONE
);
}
} elsif ($self->{config}->{ssl} eq 1) {
# SSL verification is disabled by default in LWP prior to version 6
# we activate it using Crypt::SSLeay environment variables
$ENV{HTTPS_CA_FILE} = $self->{config}->{ca};
}
bless $self;
}
sub sendXML {
my ($self, $args) = @_;
my $logger = $self->{logger};
my $compress = $self->{compress};
my $message = $args->{message};
my $common = $self->{common};
my $req = HTTP::Request->new(POST => $self->{URI});
$req->header('Pragma' => 'no-cache', 'Content-type',
'application/x-compress');
if (! $self->{config}{force}) {
# Checking if XML is valid before submitting
$logger->debug ("checking XML");
eval { XML::Simple::XMLin( $message ) };
if($@) {
my $xml_error = $@;
$xml_error =~ s/^\n//;
$logger->error ('Invalid XML: '.$xml_error);
$logger->error ('Cannot submit XML! Abort...');
return;
}
}
$logger->debug ("sending XML");
$logger->debug ("sending: ".$message);
my $compressed = $compress->compress($message);
if (!$compressed) {
$logger->error ('failed to compress data');
return;
}
$req->content($compressed);
my $res = $self->{ua}->request($req);
# Checking if connected
if (!$res->is_success) {
$logger->error ('Cannot establish communication : '.$res->status_line);
return;
}
return $res ;
}
sub getXMLResp {
my ($self, $res, $msgtype) = @_;
my $logger = $self->{logger};
my $compress = $self->{compress};
# If no answer from OCS server
return unless $res;
# Reading the XML response from OCS server
my $content = $compress->uncompress($res->content);
if (!$content) {
$logger->error ("Deflating problem");
return;
}
my $tmp = "Ocsinventory::Agent::XML::Response::".$msgtype;
eval "require $tmp";
if ($@) {
$logger->error ("Can't load response module $tmp: $@");
}
$tmp->import();
my $response = $tmp->new ({
accountconfig => $self->{accountconfig},
accountinfo => $self->{accountinfo},
content => $content,
logger => $logger,
config => $self->{config},
common => $self->{common},
});
return $response;
}
sub getFile {
my ($self,$proto,$uri,$filetoget,$filepath) = @_;
my $logger= $self->{logger};
chomp($proto,$uri,$filetoget,$filepath);
my $url = "$proto://$uri/$filetoget";
my $response = $self->{ua}->mirror($url,$filepath);
if ($response->is_success){
$logger->debug("Success downloading $filetoget file...");
} else {
$logger->error("Failed downloading $filetoget: ".$response->status_line." !!!");
return 1;
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/XML/ 0000775 0000000 0000000 00000000000 14323200667 0020445 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/XML/Inventory.pm 0000664 0000000 0000000 00000021010 14323200667 0022772 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::XML::Inventory;
# TODO: resort the functions
use strict;
use warnings;
=head1 NAME
Ocsinventory::Agent::XML::Inventory - the XML abstraction layer
=head1 DESCRIPTION
OCS Inventory uses XML for the data transmission. The module is the
abstraction layer. It's mostly used in the backend module where it
called $inventory in general.
=cut
use XML::Simple;
use Digest::MD5 qw(md5_base64);
use Config;
use Ocsinventory::Agent::Backend;
=over 4
=item new()
The usual constructor.
=cut
sub new {
my (undef, $params) = @_;
my $self = {};
$self->{accountinfo} = $params->{context}->{accountinfo};
$self->{accountconfig} = $params->{context}->{accountconfig};
$self->{backend} = $params->{backend};
$self->{common} = $params->{context}->{common};
my $logger = $self->{logger} = $params->{context}->{logger};
$self->{config} = $params->{context}->{config};
if (!($self->{config}{deviceid})) {
$logger->fault ('deviceid unititalised!');
}
$self->{xmlroot}{QUERY} = ['INVENTORY'];
$self->{xmlroot}{DEVICEID} = [$self->{config}->{deviceid}];
#$self->{xmlroot}{CONTENT}{HARDWARE} = {
# TODO move that in a backend module
# ARCHNAME => [$Config{archname}]
#};
# Is the XML centent initialised?
$self->{isInitialised} = undef;
bless $self;
}
=item initialise()
Runs the backend modules to initialise the data.
=cut
sub initialise {
my ($self) = @_;
return if $self->{isInitialised};
$self->{backend}->feedInventory ({inventory => $self});
$self->{isInitialised} = 1;
}
=item getContent()
Return the inventory as a XML string.
=cut
sub getContent {
my ($self, $args) = @_;
my $logger = $self->{logger};
my $common = $self->{common};
if ($self->{isInitialised}) {
$self->processChecksum();
# checks for MAC, NAME and SSN presence
my $macaddr = $self->{xmlroot}->{CONTENT}->{NETWORKS}->[0]->{MACADDR}->[0];
my $ssn = $self->{xmlroot}->{CONTENT}->{BIOS}->{SSN}->[0];
my $name = $self->{xmlroot}->{CONTENT}->{HARDWARE}->{NAME}->[0];
my $osname = $self->{xmlroot}->{CONTENT}->{HARDWARE}->{OSNAME}->[0];
my $missing;
$missing .= "MAC-address " unless $macaddr;
$missing .= "SSN " unless $ssn;
$missing .= "HOSTNAME " unless $name;
if ($missing) {
$logger->debug('Missing value(s): '.$missing.'. I will send this inventory to the server BUT important value(s) to identify the computer are missing');
}
$self->{accountinfo}->setAccountInfo($self);
my $content = XMLout( $self->{xmlroot}, RootName => 'REQUEST', XMLDecl => '', SuppressEmpty => undef );
# Cleaning XML to delete unprintable characters
my $clean_content = $common->cleanXml($content);
# Cleaning xmltags content after adding it o inventory
$common->flushXMLTags();
if(defined($osname) && lc($osname) eq 'macos') {
return $content;
}
return $clean_content;
}
}
=item printXML()
Only for debugging purpose. Print the inventory on STDOUT.
=cut
sub printXML {
my ($self, $args) = @_;
if ($self->{isInitialised}) {
print $self->getContent();
}
}
=item writeXML()
Save the generated inventory as an XML file. The 'local' key of the config
is used to know where the file as to be saved.
=cut
sub writeXML {
my ($self, $args) = @_;
my $logger = $self->{logger};
if ($self->{config}{local} =~ /^$/) {
$logger->fault ('local path unititalised!');
}
if ($self->{isInitialised}) {
my $localfile = $self->{config}{local}."/".$self->{config}{deviceid}.'.ocs';
$localfile =~ s!(//){1,}!/!;
# Convert perl data structure into xml strings
if (open OUT, ">$localfile") {
print OUT $self->getContent();
close OUT or warn;
$logger->info("Inventory saved in $localfile");
} else {
warn "Can't open `$localfile': $!"
}
}
}
=item processChecksum()
Compute the field. This information is used by the server to
know which parts of the XML have changed since the last inventory.
The is done thank to the last_file file. It has MD5 prints of the previous
inventory.
=cut
sub processChecksum {
my $self = shift;
my $logger = $self->{logger};
my $common = $self->{common};
# To apply to $checksum with an OR
my %mask = (
'HARDWARE' => 1,
'BIOS' => 2,
'MEMORIES' => 4,
'SLOTS' => 8,
'REGISTRY' => 16,
'CONTROLLERS' => 32,
'MONITORS' => 64,
'PORTS' => 128,
'STORAGES' => 256,
'DRIVES' => 512,
'INPUTS' => 1024,
'MODEMS' => 2048,
'NETWORKS' => 4096,
'PRINTERS' => 8192,
'SOUNDS' => 16384,
'VIDEOS' => 32768,
'SOFTWARES' => 65536,
'VIRTUALMACHINES' => 131072,
'CPUS' => 262144,
'BATTERIES' => 1048576,
);
if (!$self->{config}->{vardir}) {
$logger->fault ("vardir uninitialised!");
}
my $checksum = 0;
if (!$self->{config}{local} && $self->{config}->{last_statefile}) {
if (-f $self->{config}->{last_statefile}) {
# TODO: avoid a violant death in case of problem with XML
$self->{last_state_content} = XML::Simple::XMLin(
$self->{config}->{last_statefile},
SuppressEmpty => undef,
ForceArray => 1
);
} else {
$logger->debug ('last_state file: `'.
$self->{config}->{last_statefile}.
"' doesn't exist (yet).");
}
}
foreach my $section (keys %mask) {
# If the checksum has changed...
my $hash = md5_base64(XML::Simple::XMLout($self->{xmlroot}{'CONTENT'}{$section}));
if (!$self->{last_state_content}->{$section}[0] || $self->{last_state_content}->{$section}[0] ne $hash ) {
$logger->debug ("Section $section has changed since last inventory");
# We make OR on $checksum with the mask of the current section
$checksum |= $mask{$section};
# Finally I store the new value.
$self->{last_state_content}->{$section}[0] = $hash;
}
}
$common->setHardware({CHECKSUM => $checksum});
}
=item saveLastState()
At the end of the process IF the inventory was saved
correctly, the last_state is saved.
=cut
sub saveLastState {
my ($self, $args) = @_;
my $logger = $self->{logger};
if (!defined($self->{last_state_content})) {
$self->processChecksum();
}
if (!defined ($self->{config}->{last_statefile})) {
$logger->debug ("Can't save the last_state file. File path is not initialised.");
return;
}
if (open LAST_STATE, ">".$self->{config}->{last_statefile}) {
print LAST_STATE my $string = XML::Simple::XMLout( $self->{last_state_content}, RootName => 'LAST_STATE' );;
close LAST_STATE or warn;
} else {
$logger->debug ("Cannot save the checksum values in ".$self->{config}->{last_statefile}.":$!");
}
}
=item addSection()
A generic way to save a section in the inventory. Please avoid this
solution.
=cut
sub addSection {
my ($self, $args) = @_;
my $logger = $self->{logger};
my $multi = $args->{multi};
my $tagname = $args->{tagname};
for ( keys %{$self->{xmlroot}{CONTENT}} ){
if ( $tagname eq $_ ){
$logger->debug("Tag name `$tagname` already exists - Don't add it");
return 0;
}
}
if ($multi){
$self->{xmlroot}{CONTENT}{$tagname} = [];
} else {
$self->{xmlroot}{CONTENT}{$tagname} = {};
}
return 1;
}
=item feedSection()
Add information in inventory.
=back
=cut
# Q: is that really useful()? Can't we merge with addSection()?
sub feedSection{
my ($self, $args) = @_;
my $tagname = $args->{tagname};
my $values = $args->{data};
my $logger = $self->{logger};
my $found=0;
for ( keys %{$self->{xmlroot}{CONTENT}} ){
$found = 1 if $tagname eq $_;
}
if (!$found){
$logger->debug("Tag name `$tagname` doesn't exist - Cannot feed it");
return 0;
}
if ( $self->{xmlroot}{CONTENT}{$tagname} =~ /ARRAY/ ){
push @{$self->{xmlroot}{CONTENT}{$tagname}}, $args->{data};
} else {
$self->{xmlroot}{CONTENT}{$tagname} = $values;
}
return 1;
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/XML/Prolog.pm 0000664 0000000 0000000 00000001422 14323200667 0022244 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::XML::Prolog;
use strict;
use warnings;
use XML::Simple;
use Digest::MD5 qw(md5_base64);
sub new {
my (undef, $params) = @_;
my $self = {};
$self->{config} = $params->{context}->{config};
$self->{logger} = $params->{context}->{logger};
die unless ($self->{config}->{deviceid}); #XXX
$self->{xmlroot}{QUERY} = ['PROLOG'];
$self->{xmlroot}{DEVICEID} = [$self->{config}->{deviceid}];
bless $self;
}
sub dump {
my $self = shift;
eval "use Data::Dumper;";
print Dumper($self->{xmlroot});
}
sub getContent {
my ($self, $args) = @_;
my $content=XMLout( $self->{xmlroot}, RootName => 'REQUEST', XMLDecl => '', SuppressEmpty => undef );
return $content;
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/XML/Response.pm 0000664 0000000 0000000 00000002065 14323200667 0022604 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::XML::Response;
use strict;
use warnings;
use XML::Simple;
use Data::Dumper;
sub new {
my (undef, $params) = @_;
my $self = {};
$self->{accountconfig} = $params->{accountconfig};
$self->{accountinfo} = $params->{accountinfo};
$self->{content} = $params->{content};
$self->{config} = $params->{config};
$self->{common} = $params->{common};
my $logger = $self->{logger} = $params->{logger};
$self->{origmsg} = $params->{origmsg};
$logger->debug("=BEGIN=SERVER RET======");
$logger->debug(Dumper($self->{content}));
$logger->debug("=END=SERVER RET======");
$self->{parsedcontent} = undef;
bless $self;
}
sub getRawXML {
my $self = shift;
return $self->{content};
}
sub getParsedContent {
my ($self,$forcearray) = @_;
if (!$self->{parsedcontent}) {
$self->{parsedcontent} = $self->{common}->readXml($self->{content},$forcearray);
}
return $self->{parsedcontent};
}
sub origMsgType {
my ($self, $package) = @_;
return ref($package);
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/XML/Response/ 0000775 0000000 0000000 00000000000 14323200667 0022243 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/Agent/XML/Response/Inventory.pm 0000664 0000000 0000000 00000001072 14323200667 0024576 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::XML::Response::Inventory;
use strict;
use Ocsinventory::Agent::XML::Response;
our @ISA = ('Ocsinventory::Agent::XML::Response');
sub new {
my ($class, @params) = @_;
my $this = $class->SUPER::new(@params);
bless ($this, $class);
my $parsedContent = $this->getParsedContent(['ACCOUNTINFO']);
if ($parsedContent && exists ($parsedContent->{RESPONSE}) && $parsedContent->{RESPONSE} =~ /^ACCOUNT_UPDATE$/) {
$this->{accountinfo}->writeAccountInfoFile($parsedContent->{ACCOUNTINFO});
}
return $this;
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/XML/Response/Prolog.pm 0000664 0000000 0000000 00000005276 14323200667 0024055 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::XML::Response::Prolog;
use strict;
use Ocsinventory::Agent::XML::Response;
our @ISA = ('Ocsinventory::Agent::XML::Response');
sub new {
my ($class, @params) = @_;
my $this = $class->SUPER::new(@params);
bless ($this, $class);
$this->updatePrologFreq();
$this->saveNextTime();
return $this;
}
sub isInventoryAsked {
my $self = shift;
my $parsedContent = $self->getParsedContent(['OPTION','PARAM']);
if ($parsedContent && exists ($parsedContent->{RESPONSE}) && $parsedContent->{RESPONSE} =~ /^SEND$/) {
return 1;
}
0
}
sub getOptionsInfoByName {
my ($self, $name) = @_;
my $parsedContent = $self->getParsedContent(['OPTION','PARAM']);
my $ret = [];
return unless ($parsedContent && $parsedContent->{OPTION});
foreach (@{$parsedContent->{OPTION}}) {
if ($_->{NAME} && $_->{NAME} =~ /^$name$/i) {
$ret = $_->{PARAM}
}
}
return $ret;
}
sub updatePrologFreq {
my $self = shift;
my $parsedContent = $self->getParsedContent(['OPTION','PARAM']);
my $logger = $self->{logger};
if ($parsedContent && exists ($parsedContent->{PROLOG_FREQ})) {
if( $parsedContent->{PROLOG_FREQ} ne $self->{accountconfig}->get("PROLOG_FREQ")){
$logger->info("PROLOG_FREQ has changed since last process(old=".$self->{accountconfig}->get("PROLOG_FREQ").",new=".$parsedContent->{PROLOG_FREQ}.")");
$self->{prologFreqChanged} = 1;
$self->{accountconfig}->set("PROLOG_FREQ", $parsedContent->{PROLOG_FREQ});
} else{
$logger->debug("PROLOG_FREQ has not changed since last process");
}
}
}
sub saveNextTime {
my ($self, $args) = @_;
my $logger = $self->{logger};
if (!$self->{config}->{next_timefile}) {
$logger->debug("no next_timefile to save!");
return;
}
my $parsedContent = $self->getParsedContent(['OPTION','PARAM']);
if (!open NEXT_TIME, ">".$self->{config}->{next_timefile}) {
$logger->error ("Cannot create the next_timefile `".$self->{config}->{next_timefile}."': $!");
return;
}
close NEXT_TIME or warn;
my $serverdelay = $self->{accountconfig}->get('PROLOG_FREQ');
my $time;
if( $self->{prologFreqChanged} ){
$logger->debug("Compute next_time file with random value");
$time = time + int rand(($serverdelay?$serverdelay*3600:$self->{config}->{delaytime}));
} else{
$time = time + ($serverdelay?$serverdelay*3600:$self->{config}->{delaytime});
}
utime $time,$time,$self->{config}->{next_timefile};
if ($self->{config}->{cron}) {
$logger->info ("Next inventory after ".localtime($time));
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Agent/XML/SimpleMessage.pm 0000664 0000000 0000000 00000001741 14323200667 0023544 0 ustar 00root root 0000000 0000000 package Ocsinventory::Agent::XML::SimpleMessage;
use strict;
use warnings;
use Data::Dumper; # XXX Debug
use XML::Simple;
use Digest::MD5 qw(md5_base64);
use Ocsinventory::Agent::XML::Prolog;
sub new {
my (undef, $params) = @_;
my $self = {};
$self->{config} = $params->{config};
$self->{accountinfo} = $params->{accountinfo};
die unless ($self->{config}->{deviceid}); #XXX
$self->{xmlroot}{QUERY} = ['PROLOG'];
$self->{xmlroot}{DEVICEID} = [$self->{config}->{deviceid}];
bless $self;
}
sub dump {
my $self = shift;
print Dumper($self->{xmlroot});
}
sub set {
my ($self, $args) = @_;
foreach (keys %$args) {
$self->{xmlroot}{$_} = [$args->{$_}];
}
}
sub getContent {
my ($self, $args) = @_;
$self->{accountinfo}->setAccountInfo($self);
my $content=XMLout( $self->{xmlroot}, RootName => 'REQUEST', XMLDecl => '', SuppressEmpty => undef );
return $content;
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Compress.pm 0000664 0000000 0000000 00000005442 14323200667 0021105 0 ustar 00root root 0000000 0000000 package Ocsinventory::Compress;
use strict;
use File::Temp qw/ tempdir tempfile /;
sub new {
my (undef, $params) = @_;
my $self = {};
my $logger = $self->{logger} = $params->{logger};
eval{require Compress::Zlib;};
$self->{mode} = 'natif' unless $@;
chomp(my $gzippath=`which gzip 2>/dev/null`);
if ($self->{mode} eq 'natif') {
$logger->debug ('Compress::Zlib is available.');
} elsif (-x $gzippath) {
$logger->debug (
'Compress::Zlib is not available! The data will be compressed with
gzip instead but won\'t be accepted by server prior 1.02');
$self->{mode} = 'gzip';
$self->{tmpdir} = tempdir( CLEANUP => 1 );
mkdir $self->{tmpdir};
if ( ! -d $self->{tmpdir} ) {
$logger->fault("Failed to create the temp dir `$self->{tmpdir}'");
}
} else {
$self->{mode} = 'deflated';
$logger->debug ('I need the Compress::Zlib library or the gzip'.
' command to compress the data - The data will be sent uncompressed
but won\'t be accepted by server prior 1.02');
}
bless $self;
}
sub compress {
my ($self, $content) = @_;
my $logger = $self->{logger};
# native mode (zlib)
if ($self->{mode} eq 'natif') {
return Compress::Zlib::compress($content);
} elsif ($self->{mode} eq 'gzip'){
# gzip mode
my ($fh, $filename) = tempfile( DIR => $self->{tmpdir} );
print $fh $content;
close $fh;
system ("gzip --best $filename > /dev/null");
# print "filename ".$filename."\n";
my $ret;
open FILE, "<$filename.gz";
$ret .= $_ foreach ();
close FILE;
if ( ! unlink "$filename.gz" ) {
$logger->debug("Failed to remove `$filename.gz'");
}
return $ret;
} elsif($self->{mode} eq 'deflated'){
# No compression available
return $content;
}
}
sub uncompress {
my ($self,$data) = @_;
my $logger = $self->{logger};
# Native mode
if ($self->{mode} eq 'natif') {
return Compress::Zlib::uncompress($data);
} elsif($self->{mode} eq 'gzip'){
# Gzip mode
my ($fh, $filename) = tempfile( DIR => $self->{tmpdir}, SUFFIX => '.gz' );
print $fh $data;
close $fh;
system ("gzip -d $filename");
my ($uncompressed_filename) = $filename =~ /(.*)\.gz$/;
my $ret;
open FILE, "<$uncompressed_filename";
$ret .= $_ foreach ();
close FILE;
if ( ! unlink "$uncompressed_filename" ) {
$logger->debug("Failed to remove `$uncompressed_filename'");
}
return $ret;
} elsif($self->{mode} eq 'deflated'){
# No compression available
return $data;
}
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/Logger.pm 0000664 0000000 0000000 00000004436 14323200667 0020533 0 ustar 00root root 0000000 0000000 package Ocsinventory::Logger;
# TODO use Log::Log4perl instead.
use Carp;
sub new {
my (undef, $params) = @_;
my $self = {};
bless $self;
$self->{backend} = [];
$self->{config} = $params->{config};
$self->{debug} = $self->{config}->{debug}?1:0;
my @logger;
if (exists ($self->{config}->{logger})) {
@logger = split /,/, $self->{config}->{logger};
} else {
# if no 'logger' parameter exist I use Stderr as default backend
push @logger, 'Stderr';
}
my @loadedMbackends;
foreach (@logger) {
my $backend = "Ocsinventory::LoggerBackend::".$_;
eval ("require $backend"); # TODO deal with error
if ($@) {
print STDERR "Failed to load Logger backend: $backend ($@)\n";
next;
} else {
push @loadedMbackends, $_;
}
my $obj = new $backend ({
config => $self->{config},
});
push @{$self->{backend}}, $obj if $obj;
}
my $version = "Ocsinventory unified agent for UNIX, Linux and MacOSX ";
$version .= exists ($self->{config}->{version})?$self->{config}->{version}:'';
$self->debug($version."\n");
$self->debug("Log system initialised (@loadedMbackends)");
$self;
}
sub log {
my ($self, $args) = @_;
# levels: info, debug, warn, fault
my $level = $args->{level};
my $message = $args->{message};
my $header = $self->{header};
return if ($level =~ /^debug$/ && !($self->{debug}));
chomp($message);
#Add a header to message if needed
$message="$header $message" if $header;
$level = 'info' unless $level;
foreach (@{$self->{backend}}) {
$_->addMsg ({
level => $level,
message => $message
});
}
confess if $level =~ /^fault$/; # Die with a backtace
}
sub debug {
my ($self, $msg) = @_;
$self->log({ level => 'debug', message => $msg});
}
sub info {
my ($self, $msg) = @_;
$self->log({ level => 'info', message => $msg});
}
sub error {
my ($self, $msg) = @_;
$self->log({ level => 'error', message => $msg});
}
sub fault {
my ($self, $msg) = @_;
$self->log({ level => 'fault', message => $msg});
}
sub user {
my ($self, $msg) = @_;
$self->log({ level => 'user', message => $msg});
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/LoggerBackend/ 0000775 0000000 0000000 00000000000 14323200667 0021436 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/lib/Ocsinventory/LoggerBackend/File.pm 0000664 0000000 0000000 00000001122 14323200667 0022647 0 ustar 00root root 0000000 0000000 package Ocsinventory::LoggerBackend::File;
use strict;
sub new {
my (undef, $params) = @_;
my $self = {};
$self->{config} = $params->{config};
$self->{logfile} = $self->{config}->{logdir}."/".$self->{config}->{logfile};
bless $self;
}
sub addMsg {
my ($self, $args) = @_;
my $level = $args->{level};
my $message = $args->{message};
return if $message =~ /^$/;
open FILE, ">>".$self->{config}->{logfile} or warn "Can't open ".
"`".$self->{config}->{logfile}."'\n";
print FILE "[".localtime()."][$level] $message\n";
close FILE;
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/LoggerBackend/Stderr.pm 0000664 0000000 0000000 00000001121 14323200667 0023232 0 ustar 00root root 0000000 0000000 package Ocsinventory::LoggerBackend::Stderr;
sub new {
my (undef, $params) = @_;
my $self = {};
$self->{config} = $params->{config};
bless $self;
}
sub addMsg {
my ($self, $args) = @_;
my $level = $args->{level};
my $message = $args->{message};
return if $message =~ /^$/;
# if STDERR has been hijacked, I take its saved ref
my $stderr;
if (exists ($self->{config}->{savedstderr})) {
$stderr = $self->{config}->{savedstderr};
} else {
open ($stderr, ">&STDERR");
}
print $stderr "[$level] $message\n";
}
1;
UnixAgent-2.10.0/lib/Ocsinventory/LoggerBackend/Syslog.pm 0000664 0000000 0000000 00000001011 14323200667 0023245 0 ustar 00root root 0000000 0000000 package Ocsinventory::LoggerBackend::Syslog;
# Not tested yet!
use Sys::Syslog qw( :DEFAULT setlogsock);
sub new {
my (undef, $params) = @_;
my $self = {};
openlog("ocs-agent",'cons.pid', $params->{config}->{logfacility});
syslog('debug', 'syslog backend enabled');
bless $self;
}
sub addMsg {
my (undef, $args) = @_;
my $level = $args->{level};
my $message = $args->{message};
return if $message =~ /^$/;
syslog('info', $message);
}
sub destroy {
closelog();
}
1;
UnixAgent-2.10.0/macosx/ 0000775 0000000 0000000 00000000000 14323200667 0014771 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/macosx/README 0000664 0000000 0000000 00000003317 14323200667 0015655 0 ustar 00root root 0000000 0000000 DESCRIPTION
OS X [darwin] Readme
This README will help you roll your own native OSX, OCSNG.app client for enterprise deployment.
PREREQUISITES
- Latest XCode
- Cpanm
- Packages (Iceberg's successor)
BUILDING/INSTALLING
- Run `cpanm --install-deps .` in UnixAgent base directory
- You might need to configure cpanm if that the first configuration
- We recommend to install perl and cpanm using brew
- Move generated dependencies inside the lib directory of the OCS Inventory agent root directory
- Apply patches from macosx/patches directory
- Open the macosx/ocsng_app-xcode/OCSNG.xcodeproj and build OCSNG.app and ocscontact
- Before building check that all the external resources are available otherwise the agent won't work
COPYRIGHT
See AUTHORS file. Ocsinventory-Agent is released under GNU GPL 2 licence. Portions of the Xcode project may fall under other, open licences (individual files will elaborate). Some of the Xcode project files are not core pieces of OCSNG and are to be treated as a supplement tool for building the agent for OSX deployment.
NOTES
- macosx tools was created by claimid.com/wesyoung and modified by OCS NG team for the 2.8 version.
- Once installed, the agent should contact the server and upload an initial inventory, then go back to sleep.
- OCS MacOSX agent is launched using LaunchD but you can click on /Applications/OCSNG.app to launch OCS agent manually.
- You can take a look to OCS MacOSX logs in /var/logs/ocsng.log file (by default)
- To uninstall the .app, use the uninstaller.sh script in /Application/OCSNG/Contents/Resources directory. This will kill the service, remove all the files (no restart required).
- This package works on MacOSX 10.11+ on x86_64 architectures only.
UnixAgent-2.10.0/macosx/deps/ 0000775 0000000 0000000 00000000000 14323200667 0015724 5 ustar 00root root 0000000 0000000 UnixAgent-2.10.0/macosx/deps/darwin-perl-deps.zip 0000664 0000000 0000000 00010334443 14323200667 0021641 0 ustar 00root root 0000000 0000000 PK u:U darwin-perl-deps/UT
1cޞ1c1cux PK u:U 8 __MACOSX/._darwin-perl-depsUT
1cޞ1cӦ1cux c`cg`b`MLVVP'100i т(aul4%LPq\ĂT a`E&%d20ȝWyym֩ݞĹX[ZX'%eZ:Y:;ꚸXZ際:Z:0 PKMѡ 8 PK q:U darwin-perl-deps/Proc/UT
җ1ck1cL1cux PK q:U __MACOSX/darwin-perl-deps/._ProcUT
җ1ck1cӦ1cux c`cg`b`MLVVP'" 0CBL@l!.XPWXXWPo``almfllhjb`Ximffllklkbakifknfjhffj PKt, PK q:U darwin-perl-deps/Compress/UT
1cj1cL1cux PK q:U $ __MACOSX/darwin-perl-deps/._CompressUT
1cj1cӦ1cux c`cg`b`MLVVP'" 0CBL@l!.XPWXXWPo``almfllhjb`Ximffllklkbakifknfjhffj PKt, PK rVT ! darwin-perl-deps/AppendToPathUT
וbM1cL1cux ,.IL*J,H-w()J,736 PKB8# ! PK rVT ( __MACOSX/darwin-perl-deps/._AppendToPathUT
וbM1cӦ1cux c`cg`b`MLVVP'" 0CBL@l!.XPWXXWPo``almfllhjb`Ximffllklkbakifknfjhffj PKt, PK q:U darwin-perl-deps/Mozilla/UT
21ck1cL1cux PK q:U # __MACOSX/darwin-perl-deps/._MozillaUT
21ck1cӦ1cux c`cg`b`MLVVP'" 0CBL@l!.XPWXXWPo``almfllhjb`Ximffllklkbakifknfjhffj PKt, PK cq:U darwin-perl-deps/LWP/UT
ږ1ck1cL1cux PK cq:U __MACOSX/darwin-perl-deps/._LWPUT
ږ1ck1cӦ1cux c`cg`b`MLVVP'" 0CBL@l!.XPWXXWPo``almfllhjb`Ximffllklkbakifknfjhffj PKt, PK q7U ! darwin-perl-deps/Needs.pmUT
5-cM1cL1cux YSH]EqVbd]88k%E!x랇$?殮*y{zƉݺ7&,m{kAn
Dq8ŋFp VkzSM5]} ?Nw448qNs~$Zj#Cji~ʪV6淐-
[~l-7
?ɧ3t'[o%^B>2p0 e7+ a7sSYA(`
+^.^c{&PE2Xӿ I4ԖQrob'b~X-@G'ma!|c294hh}C*fd^3٣m?F
4W~$dw @H])8{QXlD
B,G#{?`\ܷBeҀ?y=v#=˿s-aH#xV,e4voR1FWp˸@@dH1@B`gTGk^[Oŕ`1.27G"ĺj\UCCqR,A+Lɗj_!w;ž}hòT-tUaԝUA nCEkpiz?ͧe;fe[csfYhJW|#K 0XM6E˲J˯/Wa{So@ӰMI/_S?Ƃc4 ˢ`<2,o*G&D@49?ۡ[b^\+y-&hx1sPXZi~B`|D(o>_O/'ʙM>Ov
WʞU9[66Zb.IMESҩY-W*t_ SBkc}ݴtS/H
2&kh"$nfƑ˙lA
,^%
dn~1EGR
B^tԚ|ys:QS96Ϳz>o۸8ʱ1BДCuK
9WķJ$k0wʍKʓХЗ$hVz"4o~zKKnB<"6`)C8?bpWU*}L:K&?mⅰb].gEWu+ -d!?ϩھ[[8b9a2bK
hTQ'^ꮌaID r=v9n]Xk"}0V\`E9:# \7/"Bp7s$֖yu
oEGm50 Ob[)B-cQ,4g[.YЁv}K-*ۯn<5W{?IۭWRVT_'p$0[Ql&o5WhohH^y!V+l+2y+9_"J,/לYKbKrl8oN\7"AD=*%JmjW(oR{cxr}eYƗ%Pz..J