-
Notifications
You must be signed in to change notification settings - Fork 4
/
README
126 lines (96 loc) · 4.41 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
NAME
RT-Extension-Assets-Import-CSV - RT Assets Import from CSV
PREREQUISITES
This version of RT::Extension::Assets::Import::CSV requires RT 4.4, as
that version of RT has Assets built in.
If you're running RT 4.2 with the Assets extension, you should seek an
older version of this extension; specifically, version 1.4.
INSTALLATION
perl Makefile.PL
make
make install
May need root permissions
Edit your /opt/rt5/etc/RT_SiteConfig.pm
Add this line:
Plugin('RT::Extension::Assets::Import::CSV');
See "CONFIGURATION", below, for the remainder of the required
configuration.
Restart your webserver
Run bin/rt-assets-import-csv
See bin/rt-assets-import-csv --help for more information.
CONFIGURATION
The following configuration would be used to import a three-column CSV
of assets, where the column titled serviceTag is unique:
Set( $AssetsImportUniqueCF, 'Service Tag' );
Set( %AssetsImportFieldMapping,
'Name' => 'description',
'CF.Service Tag' => 'serviceTag',
'CF.Location' => 'building',
'CF.Serial #' => 'serialNo',
);
Constant values
If you want to set an RT column or custom field to a static value for
all imported assets, precede the "CSV field name" (right hand side of
the mapping) with a slash, like so:
Set( $AssetsImportUniqueCF, 'Service Tag' );
Set( %AssetsImportFieldMapping,
'Name' => 'description',
'Catalog' => \'Hardware',
'CF.Service Tag' => 'serviceTag',
'CF.Location' => 'building',
'CF.Serial #' => 'serialNo',
);
Every imported asset will now be added to the Hardware catalog in RT.
This feature is particularly useful for setting the asset catalog, but
may also be useful when importing assets from CSV sources you don't
control (and don't want to modify each time).
Computed values
You may also compute values during import, by passing a subroutine
reference as the value in the %AssetsImportFieldMapping. This subroutine
will be called with a hash reference of the parsed CSV row.
Set( $AssetsImportUniqueCF, 'Service Tag' );
Set( %AssetsImportFieldMapping,
'Name' => 'description',
'CF.Service Tag' => 'serviceTag',
'CF.Location' => 'building',
'CF.Weight' => sub { $_[0]->{"Weight (kg)"} || "(unknown)" },
);
Using computed columns may cause false-positive "unused column"
warnings; these can be ignored.
Numeric identifiers
If you are already using a numeric identifier to uniquely track your
assets, and wish RT to take over handling of that identifier, you can
choose to leave $AssetsImportUniqueCF unset, and assign to id in the
%AssetsImportFieldMapping:
Set( %AssetsImportFieldMapping,
'id' => 'serviceTag',
'Name' => 'description',
'CF.Service Tag' => 'serviceTag',
'CF.Serial #' => 'serialNo',
);
This requires that, after the import, RT becomes the generator of all
asset ids. Otherwise, asset id conflicts may occur.
Configuring Text::CSV_XS
This extension is built upon Text::CSV_XS, which takes a number of
options for controlling its behavior. You may have a different field
delimiter, or byte-order-marking (BOM), for example, and need to enable
configuration to support it. Options set in %AssetsImportParserOptions
will be passed directly to new() in Text::CSV_XS:
Set( $AssetsImportParserOptions, {
binary => 1,
detect_bom => 1,
sep_char => '|',
});
The only default option is binary => 1. More information is available in
the Text::CSV_XS documentation.
AUTHOR
Best Practical Solutions, LLC <[email protected]>
BUGS
All bugs should be reported via email to
L<[email protected]|mailto:[email protected]>
or via the web at
L<rt.cpan.org|http://rt.cpan.org/Public/Dist/Display.html?Name=RT-Extension-Assets-Import-CSV>.
COPYRIGHT
This extension is Copyright (C) 2014-2021 Best Practical Solutions, LLC.
This is free software, licensed under:
The GNU General Public License, Version 2, June 1991