<commit_before>#!/usr/bin/php
<?php
# Generate snmpwalk of unknown devices
# requires: snmpwalk from Net-SNMP
chdir(dirname($_SERVER["SCRIPT_FILENAME"]));

define('GLPI_ROOT', '../../..');
require_once (GLPI_ROOT . "/inc/includes.php");

$snmpwalkCmd = "snmpwalk";
#$snmpwalkCmd = "ssh 192.168.14.128 --";
# you can launch snmpwalk on a remote machine through ssh:
#tunnel="0",command="/usr/bin/snmpwalk $SSH_ORIGINAL_COMMAND" ssh-rsa <KEY>== root@mysnmpmachine

$outputDir = GLPI_PLUGIN_DOC_DIR.'/fusinvsnmp/walk';

if (mkdir($outputDir) && !is_dir($outputDir)) {
  echo("Failed to create $outputDir\n");
  exit(1);
}

$t = system(sprintf("%s --version", $snmpwalkCmd));
if (!strncmp("/NET-SNMP/", $t, 7)) {
   echo "[error] snmpwalk not found. please install snmpwalk from Net-SNMP package\n";
   exit(1);
}

$sql = "SELECT ip,mac,sysdescr,snmpversion,community FROM  glpi_plugin_fusinvsnmp_unknowndevices, glpi_networkports,glpi_plugin_fusinvsnmp_configsecurities WHERE plugin_fusinvsnmp_models_id<1 AND sysdescr IS NOT NULL AND itemtype='PluginFusioninventoryUnknownDevice' AND glpi_networkports.items_id=plugin_fusioninventory_unknowndevices_id AND length(ip)>1 AND glpi_plugin_fusinvsnmp_configsecurities.id=plugin_fusinvsnmp_configsecurities_id";
$result = $DB->query($sql);
while ($host=$DB->fetch_array($result)) {

   $filePath = sprintf("%s/%s.walk", $outputDir, preg_replace('/[^a-zA-Z0-9,_-]/', '_', $host['sysdescr']));

   switch ($host['snmpversion']) {
      case 1:
         $snmpversion = '1';
         break;
      case 2:
         $snmpversion = '2c';
         break;
      default:
         printf("unsupported SNMP version: '%s'\n", $host['snmpversion']);
         continue;
   }

   $cmd = sprintf("%s -v %s -Cc -c %s %s", $snmpwalkCmd, $snmpversion, $host['community'], $host['ip']);
#   print $cmd."\n";
   printf("---\nscanning %s\n", $host['ip']);

   $fileFd = fopen($filePath, "w");
   $cmdFd = popen($cmd, "r");

   while (!feof($cmdFd)) {
      fwrite($fileFd, fgets($cmdFd));
   }
   print "done\n";

   pclose($cmdFd);
   fclose($fileFd);

   $st = stat($filePath);
   if ($st['size'] == 0) {
      unlink($filePath);
   } else {
      printf("file %s generated\n", $filePath);
   }

}<commit_msg>Fix script to create snmpwalk, have forgotten .1 in end of command to have all the SNMPWALK. Replace too filename with the IP because very hard to find in big names when create models<commit_after>#!/usr/bin/php
<?php
# Generate snmpwalk of unknown devices
# requires: snmpwalk from Net-SNMP
chdir(dirname($_SERVER["SCRIPT_FILENAME"]));

define('GLPI_ROOT', '../../..');
require_once (GLPI_ROOT . "/inc/includes.php");

$snmpwalkCmd = "snmpwalk";
#$snmpwalkCmd = "ssh 192.168.14.128 --";
# you can launch snmpwalk on a remote machine through ssh:
#tunnel="0",command="/usr/bin/snmpwalk $SSH_ORIGINAL_COMMAND" ssh-rsa <KEY>== root@mysnmpmachine

$outputDir = GLPI_PLUGIN_DOC_DIR.'/fusinvsnmp/walk';

if (mkdir($outputDir) && !is_dir($outputDir)) {
  echo("Failed to create $outputDir\n");
  exit(1);
}

$t = system(sprintf("%s --version", $snmpwalkCmd));
if (!strncmp("/NET-SNMP/", $t, 7)) {
   echo "[error] snmpwalk not found. please install snmpwalk from Net-SNMP package\n";
   exit(1);
}

$sql = "SELECT ip,mac,sysdescr,snmpversion,community FROM  glpi_plugin_fusinvsnmp_unknowndevices, glpi_networkports,glpi_plugin_fusinvsnmp_configsecurities WHERE plugin_fusinvsnmp_models_id<1 AND sysdescr IS NOT NULL AND itemtype='PluginFusioninventoryUnknownDevice' AND glpi_networkports.items_id=plugin_fusioninventory_unknowndevices_id AND length(ip)>1 AND glpi_plugin_fusinvsnmp_configsecurities.id=plugin_fusinvsnmp_configsecurities_id";
$result = $DB->query($sql);
while ($host=$DB->fetch_array($result)) {

   $filePath = sprintf("%s/%s.walk", $outputDir, $host['ip']);

   switch ($host['snmpversion']) {
      case 1:
         $snmpversion = '1';
         break;
      case 2:
         $snmpversion = '2c';
         break;
      default:
         printf("unsupported SNMP version: '%s'\n", $host['snmpversion']);
         continue;
   }

   $cmd = sprintf("%s -v %s -Cc -c %s %s .1", $snmpwalkCmd, $snmpversion, $host['community'], $host['ip']);
#   print $cmd."\n";
   printf("---\nscanning %s\n", $host['ip']);

   $fileFd = fopen($filePath, "w");
   $cmdFd = popen($cmd, "r");

   while (!feof($cmdFd)) {
      fwrite($fileFd, fgets($cmdFd));
   }
   print "done\n";

   pclose($cmdFd);
   fclose($fileFd);

   $st = stat($filePath);
   if ($st['size'] == 0) {
      unlink($filePath);
   } else {
      printf("file %s generated\n", $filePath);
   }

}
{'fraction_non_alphanumeric': 0.17520156896927436, 'fraction_numerical': 0.010459795162344738, 'mean_word_length': 4.275862068965517, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6704393', 'n_tokens_mistral': 1756, 'n_tokens_neox': 1682, 'n_words': 347}