
Beauty! Cheers!
On Wed, Nov 18, 2015 at 6:43 PM, Peter.Hine@familycourt.gov.au wrote:
Script fo changing location from the command line.
there is way too much output, so just comment out the print statements. but it works using the correct observium php functions (ref: html/pages/device/edit/device.inc.php).
########### example : ./set_custom_location.php my_device_name "oh wow"
output Observium CE 0.15.6.6430 Rename Device
Current Location : fred nerk. Current Override : 1. New Location : oh wow. Now set Location : oh wow. Now set Override : 1.
The entry in the device's logs. Device location changed: 'fred nerk' -> 'oh wow' (by console)
###########
#!/usr/bin/env php <?php
/**
- Observium
- This file is part of Observium.
- @package observium
- @subpackage cli
- @author Adam Armstrong adama@memetic.org
- @copyright (C) 2006-2015 Adam Armstrong
*/
chdir(dirname($argv[0])); $scriptname = basename($argv[0]);
include_once("includes/defaults.inc.php"); include_once("config.php");
$options = getopt("d"); if (isset($options['d'])) { array_shift($argv); } // for compatability
include_once("includes/definitions.inc.php"); include("includes/functions.inc.php");
print_message("%g".OBSERVIUM_PRODUCT." ".OBSERVIUM_VERSION."\n%WRename Device%n\n", 'color'); if (OBS_DEBUG) { print_versions(); }
// Remove a host and all related data from the system
if ($argv[1] && $argv[2]) { $host = strtolower($argv[1]); $id = get_device_id_by_hostname($host); if ($id) { $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($id));
//Current settings $currloc = get_dev_attrib($device,'override_sysLocation_string'); $curroverride = get_dev_attrib($device,'override_sysLocation_bool'); print_message("Current Location : $currloc."); print_message("Current Override : $curroverride."); $newloc = $argv[2]; print_message("New Location : $newloc."); set_dev_attrib($device, 'override_sysLocation_bool', '1'); set_dev_attrib($device, 'override_sysLocation_string', $newloc); log_event("Device location changed: '$currloc' -> '$newloc'", $id,
'device', $id, 5);
//Confirm new settings $currloc = get_dev_attrib($device,'override_sysLocation_string'); $curroverride = get_dev_attrib($device,'override_sysLocation_bool'); print_message("Now set Location : $currloc."); print_message("Now set Override : $curroverride.");
} else { print_error("Host $host doesn't exist."); } } else { print_message("%n USAGE: $scriptname hostname <new location>
%rInvalid arguments!%n", 'color', FALSE); }
// EOF
thanks
Peter Hine Senior Technical Support Engineer (Servers) FCoA ITS peter.hine@familycourt.gov.au
The information contained in this e-mail (including any attachments) is for the exclusive use of the addressee. If you are not the intended recipient please notify the sender immediately and delete this e-mail. It is noted that legal privilege is not waived because you have read this e-mail.
observium mailing list observium@observium.org http://postman.memetic.org/cgi-bin/mailman/listinfo/observium