# Converting snmpset() and snmpget() functions of php in rails

**URL:** <https://www.ruby-forum.com/t/converting-snmpset-and-snmpget-functions-of-php-in-rails/181711>\
**Category:** Rails\
**Created:** [January 16, 2010, 4:44pm UTC](https://www.ruby-forum.com/t/converting-snmpset-and-snmpget-functions-of-php-in-rails/181711 "2010-01-16T16:44:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![atheeq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/3be4f8/32.png) [@atheeq](https://www.ruby-forum.com/u/atheeq)\
**Post date:** [January 16, 2010, 4:44pm UTC](https://www.ruby-forum.com/t/converting-snmpset-and-snmpget-functions-of-php-in-rails/181711/1 "2010-01-16T16:44:48Z")

</div>

hello,

I am trying to convert a php script into a rails script. I came accross  
snmpset() and snmpget() functions and I am stuck here.

Here is a part of the php script. Please help me in converting these two  
functions.

$oid = ‘1.3.6.1.4.1.318.1.1.12.3.3.1.1.4’;  
$toret = false;  
if($pdb-\>connected) {  
$query = “SELECT snmp\_community\_str, address, reset\_port FROM  
gd\_portal\_apc\_reboot WHERE device\_id=$device\_id”;  
if($result = $pdb-\>query($query)) {  
if($pdb-\>num\_rows($result)) {  
$row = $pdb-\>get\_row($result);  
snmpset($row[‘address’], $row[‘snmp\_community\_str’],  
$oid.".".$row[‘reset\_port’], ‘i’, ‘3’);  
$count = 0;  
while($count \< 20 && $toret == false) {  
$status = snmpget($row[‘address’], $row[‘snmp\_community\_str’],  
$oid.".".$row[‘reset\_port’]);  
if($status == ‘INTEGER: 2’ || $status == ‘INTEGER: 3’) {  
sleep(1);  
$count++;  
} else if($status == ‘INTEGER: 1’) {  
$toret = true;  
} else {  
$\_SESSION[‘reboot\_error’] = ‘The server could not be  
rebooted because a proper reboot command could not be issued.’;  
$count = 20;  
}  
}  
if($count == 10) {  
$\_SESSION[‘reboot\_error’] = ‘Timed out waiting for reboot  
confirmation.’;  
}  
} else {  
$\_SESSION[‘reboot\_error’] = “Unable to locate APC for this  
server”;  
}  
$pdb-\>free\_result($result);  
} else {  
$\_SESSION[‘reboot\_error’] = “Unable to locate APC for this  
server”;  
}  
}  
return $toret;

Any help will be extremely appreciated. Thanks in advance:)
