Skip to content

Instantly share code, notes, and snippets.

@Torstein-Eide
Last active January 10, 2019 13:25
Show Gist options
  • Save Torstein-Eide/c8d96d03c1562dac6be4b15d535b1d78 to your computer and use it in GitHub Desktop.
Save Torstein-Eide/c8d96d03c1562dac6be4b15d535b1d78 to your computer and use it in GitHub Desktop.
csv to smokeping
<?php
$input = file('some_csv_file_with_3_columes.csv');
foreach ($input as $value) {
// code...
$csv[] = explode (';', $value);
}
$site = $csv[0][0];
echo "+ $site\n";
echo "menu = $site\n";
echo "title = machines in $site\n";
echo "remark = lagt med skripts\n\n";
for ($row = 0; $row < count($csv); $row++) {
echo("++ " . str_replace('.', "_", $csv[$row][2] ) );
echo("probe = FPing" . rand(1,4) . PHP_EOL); //for setup with 4 probes.
echo("host = " . $csv[$row][2]);
echo("title = " . $csv[$row][1] . PHP_EOL);
echo("menu = " . $csv[$row][1] . PHP_EOL);
echo( PHP_EOL);
}
// print_r ($csv);
// echo ("maks: " . count($csv) . PHP_EOL);
?>
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
site1;some titel;IP-address
example:
home;switch1;10.0.0.1
home;switch2;10.0.0.2
home;switch3;10.0.0.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment